├── .gitattributes ├── .github └── workflows │ └── build.yml ├── .gitignore ├── Changelog.md ├── LICENSE ├── README.md ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── release_note.txt ├── sdk-acv ├── build.gradle └── src │ └── main │ ├── java │ └── com │ │ └── webank │ │ └── wedpr │ │ └── acv │ │ ├── ACVCrypto.java │ │ ├── CoordinatorResult.java │ │ ├── CounterResult.java │ │ ├── NativeInterface.java │ │ ├── VerifierResult.java │ │ ├── VoterResult.java │ │ └── utils │ │ └── PollParametersUtil.java │ └── proto │ └── acv.proto ├── sdk-common ├── build.gradle └── src │ └── main │ └── java │ └── com │ └── webank │ └── wedpr │ └── common │ ├── NativeUtils.java │ ├── Utils.java │ ├── WedprException.java │ └── WedprResult.java ├── sdk-crypto ├── build.gradle └── src │ └── main │ ├── java │ └── com │ │ └── webank │ │ └── wedpr │ │ └── crypto │ │ ├── CryptoClient.java │ │ ├── CryptoResult.java │ │ └── NativeInterface.java │ └── resources │ └── WeDPR_dynamic_lib │ └── .blank_file ├── sdk-demo ├── build.gradle └── src │ └── main │ ├── java │ └── com │ │ └── webank │ │ └── wedpr │ │ └── demo │ │ ├── CryptoDemo.java │ │ ├── DemoMain.java │ │ ├── KtbDemo.java │ │ ├── ScdDemo.java │ │ └── VclDemo.java │ └── resources │ └── WeDPR_dynamic_lib │ └── .blank_file ├── sdk-ktb ├── build.gradle └── src │ └── main │ ├── java │ └── com │ │ └── webank │ │ └── wedpr │ │ └── ktb │ │ └── hdk │ │ ├── HdkClient.java │ │ ├── HdkResult.java │ │ └── NativeInterface.java │ └── resources │ └── WeDPR_dynamic_lib │ └── .blank_file ├── sdk-scd ├── build.gradle └── src │ └── main │ ├── java │ └── com │ │ └── webank │ │ └── wedpr │ │ └── scd │ │ ├── IssuerClient.java │ │ ├── IssuerResult.java │ │ ├── NativeInterface.java │ │ ├── PredicateType.java │ │ ├── ScdClient.java │ │ ├── UserClient.java │ │ ├── UserResult.java │ │ ├── VerifierClient.java │ │ ├── VerifierResult.java │ │ └── proto │ │ ├── AttributeDict.java │ │ ├── AttributeDictOrBuilder.java │ │ ├── BlindedCertificateSecret.java │ │ ├── BlindedCertificateSecretOrBuilder.java │ │ ├── CertificateSchema.java │ │ ├── CertificateSchemaOrBuilder.java │ │ ├── CertificateSignature.java │ │ ├── CertificateSignatureOrBuilder.java │ │ ├── CertificateTemplate.java │ │ ├── CertificateTemplateOrBuilder.java │ │ ├── Predicate.java │ │ ├── PredicateOrBuilder.java │ │ ├── Scd.java │ │ ├── ScdResult.java │ │ ├── ScdResultOrBuilder.java │ │ ├── SignCertificateRequest.java │ │ ├── SignCertificateRequestOrBuilder.java │ │ ├── StringToStringPair.java │ │ ├── StringToStringPairOrBuilder.java │ │ ├── TemplatePrivateKey.java │ │ ├── TemplatePrivateKeyOrBuilder.java │ │ ├── TemplatePublicKey.java │ │ ├── TemplatePublicKeyOrBuilder.java │ │ ├── VerificationRuleSet.java │ │ ├── VerificationRuleSetOrBuilder.java │ │ ├── VerifyRequest.java │ │ └── VerifyRequestOrBuilder.java │ └── resources │ └── WeDPR_dynamic_lib │ └── .blank_file ├── sdk-vcl ├── build.gradle └── src │ └── main │ ├── java │ └── com │ │ └── webank │ │ └── wedpr │ │ └── vcl │ │ ├── NativeInterface.java │ │ ├── VclClient.java │ │ └── VclResult.java │ └── resources │ └── WeDPR_dynamic_lib │ └── .blank_file └── settings.gradle /.gitattributes: -------------------------------------------------------------------------------- 1 | # 2 | # https://help.github.com/articles/dealing-with-line-endings/ 3 | # 4 | # These are explicitly windows files and should use crlf 5 | *.bat text eol=crlf 6 | 7 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Java-SDK GitHub Actions 2 | on: 3 | push: 4 | pull_request: 5 | release: 6 | types: [published, created, edited] 7 | env: 8 | CCACHE_DIR: ${{ github.workspace }}/ccache 9 | 10 | jobs: 11 | build: 12 | name: build 13 | runs-on: ${{ matrix.os }} 14 | strategy: 15 | matrix: 16 | os: [ubuntu-18.04, macos-latest] 17 | steps: 18 | - uses: actions/checkout@v2 19 | with: 20 | fetch-depth: 5 21 | - name: install macOS dependencies 22 | if: runner.os == 'macOS' 23 | run: brew install openjdk 24 | - name: install Ubuntu dependencies 25 | if: runner.os == 'Linux' 26 | run: sudo apt-get update && sudo apt install -y git curl default-jdk build-essential 27 | - name: download dynamic libs 28 | run: | 29 | curl -LO https://github.com/WeBankBlockchain/WeDPR-Lab-Core/releases/download/v1.1.0/java_sdk_dynamic_lib_linux.tar.gz 30 | tar zxvf java_sdk_dynamic_lib_linux.tar.gz 31 | cp ./java_sdk_dynamic_lib_linux/* ./sdk-demo/src/main/resources/WeDPR_dynamic_lib/ 32 | - name: compile and run ut 33 | run: bash ./gradlew clean build 34 | # - name: run demo 35 | # run: cd demo/dist/ && java -cp "apps/*:conf/:libs/*" com.webank.wedpr.demo.DemoMain 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | .idea/* 22 | /dist* 23 | /**/dist 24 | *.dylib 25 | *.dll 26 | *.so 27 | .DS_Store 28 | */.DS_Store 29 | 30 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 31 | hs_err_pid* 32 | 33 | # Ignore Gradle project-specific cache directory 34 | .gradle 35 | 36 | # Ignore Gradle build output directory 37 | build 38 | proto 39 | -------------------------------------------------------------------------------- /Changelog.md: -------------------------------------------------------------------------------- 1 | ## v1.4.0 2 | 3 | **新增** 4 | 5 | - 重命名子模块名称 6 | 7 | - 新增`sdk-acv`子模块,提供[WeDPR-Lab-Core](https://github.com/WeBankBlockchain/WeDPR-Lab-Core)匿名投票模块的Java接口 8 | 9 | - 上传`sdk-acv`子模块的jar包到maven仓库,jar包名称为`WeDPR-Lab-sdk-acv`,当前版本为`1.4.0`,可通过maven/gradle的方式使用匿名投票模块Java接口 10 | 11 | 12 | ## v1.3.0 13 | 14 | **WeDPR-Lab-Java-SDK v1.3.0版本**开源主要内容如下: 15 | 16 | 为KTB(Key Tool Box,密钥管理相关套件)场景式解决方案功能新增Java API和集成示例。 17 | 18 | ## v1.1.0 19 | **WeDPR-Lab-Java-SDK v1.1.0版本**开源主要内容如下: 20 | 21 | 为SCD(Selective Certificate Disclosure,选择性认证披露)场景式解决方案功能新增Java API和集成示例。 22 | 23 | 24 | ## v1.0.0 25 | 26 | **WeDPR-Lab-Java-SDK v1.0.0版本**开源主要内容如下: 27 | 28 | WeDPR-Lab的Java SDK,面向通用Java运行环境,为以下功能提供了Java API和集成示例: 29 | - VCL(Verifiable Confidential Ledger,公开可验证密文账本)场景式解决方案 30 | - 常用隐私保护算法 -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WeDPR-Lab-Java-SDK 2 | 3 | ## 如何体验WeDPR-Lab-Java-SDK 4 | 5 | WeDPR-Lab-Java-SDK是WeDPR-Lab的Java客户端。 6 | 7 | [参考文档](https://wedpr-lab.readthedocs.io/zh_CN/latest/docs/sdk/java_sdk.html) 8 | 9 | ## 环境依赖 10 | 11 | WeDPR Lab Java SDK 依赖如下: 12 | 13 | | 依赖软件 | 支持版本 | 14 | | :-: | :-: | 15 | | JAVA | JDK1.8+ | 16 | 17 | 文档中提供的预编译类库仅支持x86与x86_64架构,如需使用arm架构的动态库,需使用WeDPR-Lab-Core或WeDPR-Lab-Crypto的ffi模块编译生成动态库 18 | 19 | ## 快速体验 20 | 21 | ```bash 22 | # 下载仓库 23 | git clone https://github.com/WeBankBlockchain/WeDPR-Lab-Java-SDK.git && cd ./WeDPR-Lab-Java-SDK 24 | # 根据操作系统访问release页面获取对应动态库,以mac为例,支持mac、linux和windows版本 25 | curl -LO https://github.com/WeBankBlockchain/WeDPR-Lab-Core/releases/download/v1.1.0/java_sdk_dynamic_lib_mac.tar.gz 26 | # 解压 27 | tar zxvf java_sdk_dynamic_lib_mac.tar.gz 28 | # 拷贝动态库至加载路径 29 | cp ./java_sdk_dynamic_lib_mac/* ./demo/src/main/resources/WeDPR_dynamic_lib 30 | # 编译项目 31 | bash ./gradlew clean build 32 | # 进入项目目录 33 | cd demo/dist 34 | # 运行demo 35 | java -cp "apps/*:conf/:libs/*" com.webank.wedpr.demo.DemoMain 36 | ``` 37 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * This file was generated by the Gradle 'init' task. 3 | * 4 | * This is a general purpose Gradle build. 5 | * Learn how to create Gradle builds at https://guides.gradle.org/creating-new-gradle-builds 6 | */ 7 | plugins { 8 | id 'maven-publish' 9 | id 'java-library' 10 | id 'java' 11 | id 'org.ajoberstar.grgit' version '4.1.1' 12 | id 'com.github.sherter.google-java-format' version '0.9' 13 | id 'com.google.protobuf' version '0.8.14' 14 | } 15 | println("Notice: current gradle version is " + gradle.gradleVersion) 16 | 17 | // check.dependsOn integrationTest 18 | // integrationTest.mustRunAfter test 19 | // Additional attribute definition 20 | ext { 21 | if (!project.hasProperty("ossrhUsername")) { 22 | ossrhUsername = "xxx" 23 | } 24 | 25 | if (!project.hasProperty("ossrhPassword")) { 26 | ossrhPassword = "xxx" 27 | } 28 | junitVersion = '4.13.2' 29 | guavaVersion = '31.1-jre' 30 | protobufVersion = '3.21.5' 31 | lombokVersion = '1.18.24' 32 | protobufGradlePluginVersion = '0.8.19' 33 | protocVersion = '3.21.5' 34 | genGrpcJavaVersion = '1.48.1' 35 | } 36 | 37 | 38 | allprojects { 39 | group = 'com.webank.wedpr' 40 | version = '1.4.0' 41 | apply plugin: 'maven-publish' 42 | apply plugin: 'idea' 43 | apply plugin: 'eclipse' 44 | apply plugin: 'java' 45 | apply plugin: 'java-library' 46 | apply plugin: 'jacoco' 47 | apply plugin: 'signing' 48 | apply plugin: 'com.google.protobuf' 49 | 50 | dependencies { 51 | implementation "com.google.protobuf:protobuf-gradle-plugin:${protobufGradlePluginVersion}" 52 | } 53 | protobuf { 54 | protoc { 55 | artifact = "com.google.protobuf:protoc:${protocVersion}" 56 | } 57 | plugins { 58 | grpc { 59 | artifact = "io.grpc:protoc-gen-grpc-java:${genGrpcJavaVersion}" 60 | } 61 | } 62 | generateProtoTasks { 63 | all()*.plugins { 64 | grpc {} 65 | } 66 | } 67 | generatedFilesBaseDir = "$projectDir/proto" 68 | } 69 | 70 | configurations.all { 71 | resolutionStrategy.cacheChangingModulesFor 0, 'seconds' 72 | } 73 | 74 | jacoco { 75 | toolVersion = "0.8.6" 76 | } 77 | jacocoTestReport { 78 | reports { 79 | xml.enabled true 80 | html.enabled false 81 | } 82 | } 83 | sourceCompatibility = 1.8 84 | targetCompatibility = 1.8 85 | 86 | // In this section you declare where to find the dependencies of your project 87 | repositories { 88 | mavenCentral() 89 | maven { url "https://maven.aliyun.com/nexus/content/groups/public/" } 90 | maven { url "https://oss.sonatype.org/service/local/staging/deploy/maven2" } 91 | maven { url "https://oss.sonatype.org/content/repositories/snapshots" } 92 | } 93 | 94 | dependencies { 95 | testImplementation("junit:junit:${junitVersion}") 96 | testImplementation("com.google.guava:guava:${guavaVersion}") 97 | } 98 | 99 | clean.doLast { 100 | file("build").deleteDir() 101 | file("dist/apps/").deleteDir() 102 | file("dist/conf/").deleteDir() 103 | file("dist/lib/").deleteDir() 104 | delete protobuf.generatedFilesBaseDir 105 | } 106 | } 107 | 108 | subprojects { 109 | sourceSets { 110 | main { 111 | java { 112 | srcDir 'src/main/java' 113 | } 114 | resources { 115 | srcDir 'src/main/resources' 116 | } 117 | } 118 | } 119 | jar { 120 | destinationDir file("dist/apps") 121 | archiveName "WeDPR-Lab-" + project.name + "-" + project.version + ".jar" 122 | 123 | exclude "**/*.xml" 124 | exclude "**/*.properties" 125 | manifest { 126 | try { 127 | def repo = grgit.open(currentDir: project.rootDir) 128 | if (repo != null) { 129 | def date = new Date().format("yyyy-MM-dd'T'HH:mm:ssZ") 130 | def branch = repo.branch.getCurrent().getName() 131 | def commit = repo.head().getAbbreviatedId(40) 132 | 133 | attributes(["Implementation-Timestamp": date, 134 | "Git-Branch" : branch, 135 | "Git-Commit" : commit 136 | ]) 137 | 138 | logger.info(" Commit : ") 139 | logger.info(" => date: {}", date) 140 | logger.info(" => branch: {}", branch) 141 | logger.info(" => commit: {}", commit) 142 | } 143 | } catch (Exception e) { 144 | logger.warn(' .git not exist, cannot found commit info, e: {}', e) 145 | } 146 | } from sourceSets.main.output 147 | 148 | doLast { 149 | copy { 150 | from file("src/test/resources/") 151 | into "dist/conf" 152 | } 153 | copy { 154 | from configurations.runtimeClasspath 155 | into "dist/lib" 156 | } 157 | copy { 158 | from file("build/libs/") 159 | into "dist/apps" 160 | } 161 | } 162 | } 163 | clean.doLast { 164 | file("build").deleteDir() 165 | file("dist/apps/").deleteDir() 166 | file("dist/conf/").deleteDir() 167 | file("dist/lib/").deleteDir() 168 | } 169 | } 170 | 171 | dependencies { 172 | testImplementation("junit:junit:${junitVersion}") 173 | testImplementation("com.google.guava:guava:${guavaVersion}") 174 | implementation("com.google.protobuf:protobuf-java:${protobufVersion}") 175 | implementation("org.projectlombok:lombok:${lombokVersion}") 176 | } 177 | 178 | sourceSets { 179 | main { 180 | java { 181 | srcDir "sdk-common/src/main/java" 182 | srcDir "sdk-crypto/src/main/java" 183 | srcDir "sdk-vcl/src/main/java" 184 | srcDir "sdk-scd/src/main/java" 185 | srcDir "sdk-ktb/src/main/java" 186 | srcDir "sdk-acv/src/main/java" 187 | srcDir "proto/main/java/com/webank/wedpr/acv/proto/" 188 | } 189 | proto { 190 | srcDir "sdk-acv/src/main/proto" 191 | } 192 | buildscript 193 | resources { 194 | srcDir 'src/main/resources' 195 | } 196 | } 197 | } 198 | googleJavaFormat { 199 | toolVersion = '1.7' 200 | options style: 'AOSP' 201 | source = sourceSets*.allJava 202 | include 'common/*.java' 203 | } 204 | javadoc { 205 | options.addStringOption('Xdoclint:none', '-quiet') 206 | options.addStringOption('encoding', 'UTF-8') 207 | options.addStringOption('charSet', 'UTF-8') 208 | } 209 | 210 | task sourcesJar(type: Jar) { 211 | from sourceSets.main.allJava 212 | archiveClassifier = 'sources' 213 | } 214 | 215 | task javadocJar(type: Jar) { 216 | from javadoc 217 | archiveClassifier = 'javadoc' 218 | } 219 | 220 | publishing { 221 | publications { 222 | mavenJava(MavenPublication) { 223 | 224 | artifactId project.name 225 | groupId project.group 226 | version project.version 227 | 228 | from components.java 229 | artifact sourcesJar 230 | artifact javadocJar 231 | pom { 232 | name = 'WeDPR-Lab-Java-SDK' 233 | description = 'WeDPR-Lab-Java-SDK' 234 | url = 'http://www.fisco-bcos.org' 235 | 236 | licenses { 237 | license { 238 | name = 'The Apache License, Version 2.0' 239 | url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' 240 | } 241 | } 242 | developers { 243 | developer { 244 | id = 'zhangsan' 245 | name = 'zhangsan' 246 | email = 'zhangsan@example.com' 247 | } 248 | } 249 | scm { 250 | connection = 'https://github.com/WeBankBlockchain/WeDPR-Lab-Java-SDK' 251 | url = 'https://github.com/WeBankBlockchain/WeDPR-Lab-Java-SDK' 252 | } 253 | } 254 | } 255 | } 256 | repositories { 257 | maven { 258 | def releasesRepoURL = "https://oss.sonatype.org/service/local/staging/deploy/maven2" 259 | def snapshotsRepoURL = "https://oss.sonatype.org/content/repositories/snapshots" 260 | url = !version.endsWith("SNAPSHOT") ? releasesRepoURL : snapshotsRepoURL 261 | 262 | credentials { 263 | username ossrhUsername 264 | password ossrhPassword 265 | } 266 | } 267 | } 268 | 269 | signing { 270 | sign publishing.publications.mavenJava 271 | } 272 | } 273 | 274 | jar { 275 | // destinationDir file('dist/apps') 276 | archiveName project.name + '-' + project.version + '.jar' 277 | exclude '**/*.xml' 278 | exclude '**/*.properties' 279 | 280 | manifest { 281 | try { 282 | def repo = grgit.open(currentDir: project.rootDir) 283 | if (repo != null) { 284 | def date = new Date().format("yyyy-MM-dd'T'HH:mm:ssZ") 285 | def branch = repo.branch.getCurrent().getName() 286 | def commit = repo.head().getAbbreviatedId(40) 287 | 288 | attributes(["Implementation-Timestamp": date, 289 | "Git-Branch" : branch, 290 | "Git-Commit" : commit 291 | ]) 292 | 293 | logger.info(" Commit : ") 294 | logger.info(" => date: {}", date) 295 | logger.info(" => branch: {}", branch) 296 | logger.info(" => commit: {}", commit) 297 | } 298 | } catch (Exception e) { 299 | logger.warn(' .git not exist, cannot found commit info, e: {}', e) 300 | } 301 | } from sourceSets.main.output 302 | 303 | doLast { 304 | copy { 305 | from destinationDirectory 306 | into 'dist/apps' 307 | } 308 | copy { 309 | from configurations.runtimeClasspath 310 | into 'dist/lib' 311 | } 312 | copy { 313 | from file('src/test/resources/config-example.toml') 314 | from file('src/test/resources/clog.ini') 315 | from file('src/test/resources/applicationContext-sample.xml') 316 | from file('src/test/resources/log4j.properties') 317 | into 'dist/conf' 318 | } 319 | } 320 | } 321 | check.dependsOn jacocoTestReport 322 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WeBankBlockchain/WeDPR-Lab-Java-SDK/2adc80bf560a87a34778b8da93ba91549e33edfe/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Sep 15 19:29:08 CST 2020 2 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip 3 | distributionBase=GRADLE_USER_HOME 4 | distributionPath=wrapper/dists 5 | zipStorePath=wrapper/dists 6 | zipStoreBase=GRADLE_USER_HOME 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /release_note.txt: -------------------------------------------------------------------------------- 1 | v1.4.0 2 | -------------------------------------------------------------------------------- /sdk-acv/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | } 4 | dependencies { 5 | api project(':sdk-common') 6 | implementation project(':sdk-common') 7 | implementation("com.google.protobuf:protobuf-java:${protobufVersion}") 8 | } 9 | task sourcesJar(type: Jar) { 10 | from sourceSets.main.allJava 11 | archiveClassifier = 'sources' 12 | } 13 | 14 | task javadocJar(type: Jar) { 15 | from javadoc 16 | archiveClassifier = 'javadoc' 17 | } 18 | 19 | publishing { 20 | publications { 21 | mavenJava(MavenPublication) { 22 | 23 | artifactId "WeDPR-Lab-" + project.name 24 | groupId project.group 25 | version project.version 26 | 27 | from components.java 28 | artifact sourcesJar 29 | artifact javadocJar 30 | pom { 31 | name = 'WeDPR-Lab-Java-SDK' 32 | description = 'WeDPR-Lab-Java-SDK' 33 | url = 'http://www.fisco-bcos.org' 34 | 35 | licenses { 36 | license { 37 | name = 'The Apache License, Version 2.0' 38 | url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' 39 | } 40 | } 41 | developers { 42 | developer { 43 | id = 'zhangsan' 44 | name = 'zhangsan' 45 | email = 'zhangsan@example.com' 46 | } 47 | } 48 | scm { 49 | connection = 'https://github.com/WeBankBlockchain/WeDPR-Lab-Java-SDK' 50 | url = 'https://github.com/WeBankBlockchain/WeDPR-Lab-Java-SDK' 51 | } 52 | } 53 | } 54 | } 55 | repositories { 56 | maven { 57 | def releasesRepoURL = "https://oss.sonatype.org/service/local/staging/deploy/maven2" 58 | def snapshotsRepoURL = "https://oss.sonatype.org/content/repositories/snapshots" 59 | url = !version.endsWith("SNAPSHOT") ? releasesRepoURL : snapshotsRepoURL 60 | 61 | credentials { 62 | username ossrhUsername 63 | password ossrhPassword 64 | } 65 | } 66 | } 67 | 68 | signing { 69 | sign publishing.publications.mavenJava 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /sdk-acv/src/main/java/com/webank/wedpr/acv/ACVCrypto.java: -------------------------------------------------------------------------------- 1 | package com.webank.wedpr.acv; 2 | 3 | import com.google.protobuf.ByteString; 4 | import com.google.protobuf.InvalidProtocolBufferException; 5 | import com.webank.wedpr.acv.NativeInterface; 6 | import com.webank.wedpr.acv.proto.Acv; 7 | import com.webank.wedpr.acv.proto.Ballot; 8 | import com.webank.wedpr.acv.proto.CandidateList; 9 | import com.webank.wedpr.acv.proto.CounterSecret; 10 | import com.webank.wedpr.acv.proto.DecryptedResultPartStorage; 11 | import com.webank.wedpr.acv.proto.PollParametersStorage; 12 | import com.webank.wedpr.acv.proto.RegistrationBlindingPoint; 13 | import com.webank.wedpr.acv.proto.RegistrationRequest; 14 | import com.webank.wedpr.acv.proto.RegistrationResponse; 15 | import com.webank.wedpr.acv.proto.VoteChoice; 16 | import com.webank.wedpr.acv.proto.VoteRequest; 17 | import com.webank.wedpr.acv.proto.VoteResultStorage; 18 | import com.webank.wedpr.acv.proto.VoteStorage; 19 | import com.webank.wedpr.acv.proto.VoterSecret; 20 | import com.webank.wedpr.common.Utils; 21 | import com.webank.wedpr.common.WedprException; 22 | 23 | public class ACVCrypto 24 | { 25 | 26 | private static NativeInterface nativeInterface; 27 | 28 | // coordinator related interfaces 29 | public static CoordinatorResult makePollParameters(CandidateList candidateList, PollParametersStorage counterParameters) 30 | { 31 | return nativeInterface.makePollParameters(Utils.bytesToString(candidateList.toByteArray()), Utils.bytesToString(counterParameters.toByteArray())); 32 | } 33 | 34 | public static CoordinatorResult certifyVoter(byte[] secretKey, RegistrationRequest registrationRequest, int voterWeight) 35 | { 36 | return nativeInterface.certifyVoter(secretKey, Utils.bytesToString(registrationRequest.toByteArray()), voterWeight); 37 | } 38 | 39 | public static CoordinatorResult certifyUnboundedVoter(byte[] secretKey, RegistrationRequest registrationRequest, int voterWeight) 40 | { 41 | return nativeInterface.certifyUnboundedVoter(secretKey, Utils.bytesToString(registrationRequest.toByteArray()), voterWeight); 42 | } 43 | 44 | public static CoordinatorResult aggregateVoteSumResponse(PollParametersStorage pollParameters, VoteStorage votePart, VoteStorage voteSum) 45 | { 46 | return nativeInterface.aggregateVoteSumResponse(Utils.bytesToString(pollParameters.toByteArray()), Utils.bytesToString(votePart.toByteArray()), Utils.bytesToString(voteSum.toByteArray())); 47 | } 48 | 49 | 50 | public static CoordinatorResult aggregateVoteSumResponseUnlisted(PollParametersStorage pollParameters, VoteStorage votePart, VoteStorage voteSum) 51 | { 52 | return nativeInterface.aggregateVoteSumResponseUnlisted(Utils.bytesToString(pollParameters.toByteArray()), Utils.bytesToString(votePart.toByteArray()), Utils.bytesToString(voteSum.toByteArray())); 53 | } 54 | 55 | public static CoordinatorResult aggregateDecryptedPartSum(PollParametersStorage pollParameters, DecryptedResultPartStorage partiallyDecryptedResult, DecryptedResultPartStorage aggregatedDecryptedResult) 56 | { 57 | return nativeInterface.aggregateDecryptedPartSum(Utils.bytesToString(pollParameters.toByteArray()), Utils.bytesToString(partiallyDecryptedResult.toByteArray()), Utils.bytesToString(aggregatedDecryptedResult.toByteArray())); 58 | } 59 | 60 | public static CoordinatorResult aggregateDecryptedPartSumUnlisted(PollParametersStorage pollParameters, DecryptedResultPartStorage partiallyDecryptedResult, DecryptedResultPartStorage aggregatedDecryptedResult) 61 | { 62 | return nativeInterface.aggregateDecryptedPartSumUnlisted(Utils.bytesToString(pollParameters.toByteArray()), Utils.bytesToString(partiallyDecryptedResult.toByteArray()), Utils.bytesToString(aggregatedDecryptedResult.toByteArray())); 63 | } 64 | 65 | public static CoordinatorResult finalizeVoteResult(PollParametersStorage pollParameters, VoteStorage voteSum, DecryptedResultPartStorage aggregatedDecryptedResult, long maxVoteLimit) 66 | { 67 | return nativeInterface.finalizeVoteResult(Utils.bytesToString(pollParameters.toByteArray()), Utils.bytesToString(voteSum.toByteArray()), Utils.bytesToString(aggregatedDecryptedResult.toByteArray()), maxVoteLimit); 68 | } 69 | public static CoordinatorResult finalizeVoteResultUnlisted(PollParametersStorage pollParameters, VoteStorage voteSum, DecryptedResultPartStorage aggregatedDecryptedResult, long maxVoteLimit, long maxCandidateNum) 70 | { 71 | return nativeInterface.finalizeVoteResultUnlisted(Utils.bytesToString(pollParameters.toByteArray()), Utils.bytesToString(voteSum.toByteArray()), Utils.bytesToString(aggregatedDecryptedResult.toByteArray()), maxVoteLimit, maxCandidateNum); 72 | } 73 | 74 | // counter related interfaces 75 | public static CounterResult makeCounterSecret() 76 | { 77 | return nativeInterface.makeCounterSecret(); 78 | } 79 | 80 | public static CounterResult makeCounterParametersShare(String counterID, CounterSecret counterSecret) 81 | { 82 | return nativeInterface.makeCounterParametersShare(counterID, Utils.bytesToString(counterSecret.toByteArray())); 83 | } 84 | 85 | public static CounterResult count(String counterID, CounterSecret counterSecret, VoteStorage encryptedVoteSum) 86 | { 87 | return nativeInterface.count(counterID, Utils.bytesToString(counterSecret.toByteArray()), Utils.bytesToString(encryptedVoteSum.toByteArray())); 88 | } 89 | public static CounterResult countUnlisted(String counterID, CounterSecret counterSecret, VoteStorage encryptedVoteSum) 90 | { 91 | return nativeInterface.countUnlisted(counterID, Utils.bytesToString(counterSecret.toByteArray()), Utils.bytesToString(encryptedVoteSum.toByteArray())); 92 | } 93 | 94 | /// verifier related interfaces 95 | public static VerifierResult verifyVoteRequest(PollParametersStorage pollParameters, VoteRequest voteRequest, byte[] publicKey) 96 | { 97 | return nativeInterface.verifyVoteRequest(Utils.bytesToString(pollParameters.toByteArray()), Utils.bytesToString(voteRequest.toByteArray()), publicKey); 98 | } 99 | public static VerifierResult verifyUnboundedVoteRequest(PollParametersStorage pollParameters, VoteRequest voteRequest, byte[] publicKey) 100 | { 101 | return nativeInterface.verifyUnboundedVoteRequest(Utils.bytesToString(pollParameters.toByteArray()), Utils.bytesToString(voteRequest.toByteArray()), publicKey); 102 | } 103 | public static VerifierResult verifyUnboundedVoteRequestUnlisted(PollParametersStorage pollParameters, VoteRequest voteRequest, byte[] publicKey) 104 | { 105 | return nativeInterface.verifyUnboundedVoteRequestUnlisted(Utils.bytesToString(pollParameters.toByteArray()), Utils.bytesToString(voteRequest.toByteArray()), publicKey); 106 | } 107 | public static VerifierResult verifyCountRequest(PollParametersStorage pollParameters, VoteStorage encryptedVoteSum, byte[] counterShared, DecryptedResultPartStorage partiallyDecryptedResult) 108 | { 109 | return nativeInterface.verifyCountRequest(Utils.bytesToString(pollParameters.toByteArray()), Utils.bytesToString(encryptedVoteSum.toByteArray()), counterShared, Utils.bytesToString(partiallyDecryptedResult.toByteArray())); 110 | } 111 | public static VerifierResult verifyCountRequestUnlisted(PollParametersStorage pollParameters, VoteStorage encryptedVoteSum, byte[] counterShared, DecryptedResultPartStorage partiallyDecryptedResult) 112 | { 113 | return nativeInterface.verifyCountRequestUnlisted(Utils.bytesToString(pollParameters.toByteArray()), Utils.bytesToString(encryptedVoteSum.toByteArray()), counterShared, Utils.bytesToString(partiallyDecryptedResult.toByteArray())); 114 | 115 | } 116 | public static VerifierResult verifyVoteResult(PollParametersStorage pollParameters, VoteStorage voteSum, DecryptedResultPartStorage aggregatedDecryptedResult, VoteResultStorage voteResult) 117 | { 118 | return nativeInterface.verifyVoteResult(Utils.bytesToString(pollParameters.toByteArray()), Utils.bytesToString(voteSum.toByteArray()), Utils.bytesToString(aggregatedDecryptedResult.toByteArray()), Utils.bytesToString(voteResult.toByteArray())); 119 | } 120 | 121 | public static VerifierResult verifyBlankBallot(RegistrationRequest registrationRequest, RegistrationResponse registrationResponse) 122 | { 123 | return nativeInterface.verifyBlankBallot(Utils.bytesToString(registrationRequest.toByteArray()), Utils.bytesToString(registrationResponse.toByteArray())); 124 | } 125 | 126 | /// voter related interfaces 127 | public static VoterResult makeVoterSecret() 128 | { 129 | return nativeInterface.makeVoterSecret(); 130 | } 131 | 132 | public static VoterResult generateRegistrationBlindingPoint(VoterSecret voterSecret, PollParametersStorage pollParameters) 133 | { 134 | return nativeInterface.generateRegistrationBlindingPoint(Utils.bytesToString(voterSecret.toByteArray()), Utils.bytesToString(pollParameters.toByteArray())); 135 | } 136 | public static VoterResult makeUnboundedRegistrationRequest(VoterSecret zeroSecret, VoterSecret voterSecret, PollParametersStorage pollParameters) 137 | { 138 | return nativeInterface.makeUnboundedRegistrationRequest(Utils.bytesToString(zeroSecret.toByteArray()), Utils.bytesToString(voterSecret.toByteArray()), Utils.bytesToString(pollParameters.toByteArray())); 139 | } 140 | public static VoterResult vote(VoterSecret voterSecret, VoteChoice voteChoice, RegistrationResponse registrationResponse, PollParametersStorage pollParameters) 141 | { 142 | return nativeInterface.vote(Utils.bytesToString(voterSecret.toByteArray()), Utils.bytesToString(voteChoice.toByteArray()), Utils.bytesToString(registrationResponse.toByteArray()), Utils.bytesToString(pollParameters.toByteArray())); 143 | } 144 | public static VoterResult voteUnbounded(VoterSecret voterSecret, VoterSecret zeroSecret, VoteChoice voteChoice, RegistrationResponse registrationResponse, PollParametersStorage pollParameters) 145 | { 146 | return nativeInterface.voteUnbounded(Utils.bytesToString(voterSecret.toByteArray()), Utils.bytesToString(zeroSecret.toByteArray()), Utils.bytesToString(voteChoice.toByteArray()), Utils.bytesToString(registrationResponse.toByteArray()), Utils.bytesToString(pollParameters.toByteArray())); 147 | } 148 | public static VoterResult voteUnboundedUnlisted(VoterSecret voterSecret, VoterSecret zeroSecret, VoteChoice voteChoice, RegistrationResponse registrationResponse, PollParametersStorage pollParameters) 149 | { 150 | return nativeInterface.voteUnboundedUnlisted(Utils.bytesToString(voterSecret.toByteArray()), Utils.bytesToString(zeroSecret.toByteArray()), Utils.bytesToString(voteChoice.toByteArray()), Utils.bytesToString(registrationResponse.toByteArray()), Utils.bytesToString(pollParameters.toByteArray())); 151 | } 152 | 153 | public static boolean verifyWeightBallot(int weightValue, byte[] weightBlindingPoint, byte[] weightBlindingPointG2, String voteRequest) throws InvalidProtocolBufferException, WedprException { 154 | RegistrationBlindingPoint weightPoint = RegistrationBlindingPoint.newBuilder(). 155 | setBlindingPollPoint(ByteString.copyFrom(weightBlindingPoint)). 156 | setBlindingBasepointG2(ByteString.copyFrom(weightBlindingPointG2)).build(); 157 | RegistrationRequest registrationRequest = RegistrationRequest.newBuilder().setWeightPoint(weightPoint).build(); 158 | 159 | VoteRequest voteRequestPb = VoteRequest.parseFrom(Utils.stringToBytes(voteRequest)); 160 | Ballot ballot = 161 | Ballot.newBuilder() 162 | .setCiphertext1(voteRequestPb.getVote().getBlankBallot().getCiphertext1()) 163 | .setCiphertext2(voteRequestPb.getVote().getBlankBallot().getCiphertext2()) 164 | .build(); 165 | 166 | RegistrationResponse registrationResponse = 167 | RegistrationResponse.newBuilder() 168 | .setVoterWeight(weightValue) 169 | .setBallot(ballot) 170 | .build(); 171 | 172 | VerifierResult verifierResult = 173 | ACVCrypto.verifyBlankBallot( 174 | registrationRequest, 175 | registrationResponse); 176 | if(verifierResult.hasError()) 177 | { 178 | String errorMsg = "verifyWeightBallot error, error: " + verifierResult.wedprErrorMessage + 179 | "weightValue: " + weightValue + "voteRequest: " + voteRequest; 180 | throw new WedprException(errorMsg); 181 | } 182 | return verifierResult.verifyResult; 183 | } 184 | } -------------------------------------------------------------------------------- /sdk-acv/src/main/java/com/webank/wedpr/acv/CoordinatorResult.java: -------------------------------------------------------------------------------- 1 | // Copyright 2022 WeDPR Lab Project Authors. Licensed under Apache-2.0. 2 | 3 | package com.webank.wedpr.acv; 4 | 5 | import com.google.protobuf.InvalidProtocolBufferException; 6 | import com.webank.wedpr.acv.proto.DecryptedResultPartStorage; 7 | import com.webank.wedpr.acv.proto.PollParametersStorage; 8 | import com.webank.wedpr.acv.proto.RegistrationResponse; 9 | import com.webank.wedpr.acv.proto.VoteResultStorage; 10 | import com.webank.wedpr.acv.proto.VoteStorage; 11 | import com.webank.wedpr.common.Utils; 12 | import com.webank.wedpr.common.WedprException; 13 | import com.webank.wedpr.common.WedprResult; 14 | 15 | /** 16 | * Result class used by VCL client. 17 | * 18 | *

This is an easy way to return multiple data from a single JNI interface. 19 | */ 20 | public class CoordinatorResult extends WedprResult { 21 | public String poll_parameters; 22 | public String registration_response; 23 | public String vote_sum; 24 | public String aggregated_decrypted_result; 25 | public String vote_result; 26 | 27 | /** Expects no error occurred, otherwise throws an Exception. */ 28 | public CoordinatorResult expectNoError() throws WedprException { 29 | if (hasError()) { 30 | throw new WedprException(wedprErrorMessage); 31 | } 32 | return this; 33 | } 34 | 35 | public String getPoll_parameters() { 36 | return poll_parameters; 37 | } 38 | 39 | public void setPoll_parameters(String poll_parameters) { 40 | this.poll_parameters = poll_parameters; 41 | } 42 | 43 | public String getRegistration_response() { 44 | return registration_response; 45 | } 46 | 47 | public void setRegistration_response(String registration_response) { 48 | this.registration_response = registration_response; 49 | } 50 | 51 | public String getVote_sum() { 52 | return vote_sum; 53 | } 54 | 55 | public void setVote_sum(String vote_sum) { 56 | this.vote_sum = vote_sum; 57 | } 58 | 59 | public String getAggregated_decrypted_result() { 60 | return aggregated_decrypted_result; 61 | } 62 | 63 | public void setAggregated_decrypted_result(String aggregated_decrypted_result) { 64 | this.aggregated_decrypted_result = aggregated_decrypted_result; 65 | } 66 | 67 | public String getVote_result() { 68 | return vote_result; 69 | } 70 | 71 | public void setVote_result(String vote_result) { 72 | this.vote_result = vote_result; 73 | } 74 | 75 | public PollParametersStorage getPollParameters() throws InvalidProtocolBufferException 76 | { 77 | if(poll_parameters.isEmpty()) 78 | { 79 | return null; 80 | } 81 | return PollParametersStorage.parseFrom(Utils.stringToBytes(poll_parameters)); 82 | } 83 | 84 | public RegistrationResponse getRegistrationResponse()throws InvalidProtocolBufferException 85 | { 86 | if(registration_response.isEmpty()) 87 | { 88 | return null; 89 | } 90 | return RegistrationResponse.parseFrom(Utils.stringToBytes(registration_response)); 91 | } 92 | 93 | public VoteStorage getVoteSum() throws InvalidProtocolBufferException 94 | { 95 | if(vote_sum.isEmpty()) 96 | { 97 | return null; 98 | } 99 | return VoteStorage.parseFrom(Utils.stringToBytes(vote_sum)); 100 | } 101 | 102 | public DecryptedResultPartStorage getAggregatedDecryptedResult() throws InvalidProtocolBufferException 103 | { 104 | if(aggregated_decrypted_result.isEmpty()) 105 | { 106 | return null; 107 | } 108 | return DecryptedResultPartStorage.parseFrom(Utils.stringToBytes(aggregated_decrypted_result)); 109 | } 110 | 111 | public VoteResultStorage getVoteResult() throws InvalidProtocolBufferException 112 | { 113 | if(vote_result.isEmpty()) 114 | { 115 | return null; 116 | } 117 | return VoteResultStorage.parseFrom(Utils.stringToBytes(vote_result)); 118 | } 119 | } -------------------------------------------------------------------------------- /sdk-acv/src/main/java/com/webank/wedpr/acv/CounterResult.java: -------------------------------------------------------------------------------- 1 | // Copyright 2022 WeDPR Lab Project Authors. Licensed under Apache-2.0. 2 | 3 | package com.webank.wedpr.acv; 4 | 5 | import com.google.protobuf.InvalidProtocolBufferException; 6 | import com.webank.wedpr.acv.proto.CounterParametersShareRequest; 7 | import com.webank.wedpr.acv.proto.CounterSecret; 8 | import com.webank.wedpr.acv.proto.DecryptedResultPartStorage; 9 | import com.webank.wedpr.common.Utils; 10 | import com.webank.wedpr.common.WedprException; 11 | import com.webank.wedpr.common.WedprResult; 12 | 13 | /** 14 | * Result class used by VCL client. 15 | * 16 | *

This is an easy way to return multiple data from a single JNI interface. 17 | */ 18 | public class CounterResult extends WedprResult { 19 | public String counter_secret; 20 | public String counter_parameters_share; 21 | public String counter_decrypted_result; 22 | 23 | /** Expects no error occurred, otherwise throws an Exception. */ 24 | public CounterResult expectNoError() throws WedprException { 25 | if (hasError()) { 26 | throw new WedprException(wedprErrorMessage); 27 | } 28 | return this; 29 | } 30 | 31 | public String getCounter_secret() { 32 | return counter_secret; 33 | } 34 | 35 | public void setCounter_secret(String counter_secret) { 36 | this.counter_secret = counter_secret; 37 | } 38 | 39 | public String getCounter_parameters_share() { 40 | return counter_parameters_share; 41 | } 42 | 43 | public void setCounter_parameters_share(String counter_parameters_share) { 44 | this.counter_parameters_share = counter_parameters_share; 45 | } 46 | 47 | public String getCounter_decrypted_result() { 48 | return counter_decrypted_result; 49 | } 50 | 51 | public void setCounter_decrypted_result(String counter_decrypted_result) { 52 | this.counter_decrypted_result = counter_decrypted_result; 53 | } 54 | 55 | public CounterSecret getCounterSecret() throws InvalidProtocolBufferException 56 | { 57 | if(counter_secret.isEmpty()) 58 | { 59 | return null; 60 | } 61 | return CounterSecret.parseFrom(Utils.stringToBytes(counter_secret)); 62 | } 63 | 64 | public CounterParametersShareRequest getCounterParametersShare() throws InvalidProtocolBufferException 65 | { 66 | if(counter_parameters_share.isEmpty()) 67 | { 68 | return null; 69 | } 70 | return CounterParametersShareRequest.parseFrom(Utils.stringToBytes(counter_parameters_share)); 71 | } 72 | public DecryptedResultPartStorage getCounterDecryptedResult() throws InvalidProtocolBufferException 73 | { 74 | if(counter_decrypted_result.isEmpty()) 75 | { 76 | return null; 77 | } 78 | return DecryptedResultPartStorage.parseFrom(Utils.stringToBytes(counter_decrypted_result)); 79 | } 80 | } -------------------------------------------------------------------------------- /sdk-acv/src/main/java/com/webank/wedpr/acv/NativeInterface.java: -------------------------------------------------------------------------------- 1 | // Copyright 2022 WeDPR Lab Project Authors. Licensed under Apache-2.0. 2 | 3 | package com.webank.wedpr.acv; 4 | 5 | import com.webank.wedpr.common.NativeUtils; 6 | import java.io.IOException; 7 | import com.webank.wedpr.acv.CoordinatorResult; 8 | import com.webank.wedpr.acv.CounterResult; 9 | import com.webank.wedpr.acv.VerifierResult; 10 | import com.webank.wedpr.acv.VoterResult; 11 | 12 | public class NativeInterface 13 | { 14 | private static final String LIB_NAME = "WeDPR_dynamic_lib/"; 15 | static { 16 | try { 17 | // Load the dynamic library of VCL on different operating systems. 18 | String osName = System.getProperty("os.name").toLowerCase(); 19 | String libPostFix; 20 | if (osName.contains("windows")) { 21 | libPostFix = "ffi_java_acv.dll"; 22 | } else if (osName.contains("linux")) { 23 | libPostFix = "libffi_java_acv.so"; 24 | } else if (osName.contains("mac")) { 25 | libPostFix = "libffi_java_acv.dylib"; 26 | } else { 27 | throw new IOException( 28 | String.format("Operating system %s is not supported.", osName)); 29 | } 30 | String libPathInJar = LIB_NAME + libPostFix; 31 | NativeUtils.loadLibrary(libPathInJar); 32 | } catch (IOException e) { 33 | // TODO: Provide more instructions on resolving dynamic library loading errors. 34 | throw new RuntimeException(e); 35 | } 36 | } 37 | // coordinator related interfaces 38 | public static native CoordinatorResult makePollParameters(String candidateList, String counterParameters); 39 | public static native CoordinatorResult certifyVoter(byte[] secretKey, String registrationRequest, int voterWeight); 40 | public static native CoordinatorResult certifyUnboundedVoter(byte[] secretKey, String registrationRequest, int voterWeight); 41 | public static native CoordinatorResult aggregateVoteSumResponse(String pollParameters, String votePart, String voteSum); 42 | public static native CoordinatorResult aggregateVoteSumResponseUnlisted(String pollParameters, String votePart, String voteSum); 43 | public static native CoordinatorResult aggregateDecryptedPartSum(String pollParameters, String partiallyDecryptedResult, String aggregatedDecryptedResult); 44 | public static native CoordinatorResult aggregateDecryptedPartSumUnlisted(String pollParameters, String partiallyDecryptedResult, String aggregatedDecryptedResult); 45 | public static native CoordinatorResult finalizeVoteResult(String poolParameters, String voterSum, String aggregatedDecryptedResult, long maxVoteLimit); 46 | public static native CoordinatorResult finalizeVoteResultUnlisted(String pollParameters, String voteSum, String aggregatedDecryptedResult, long maxVoteLimit, long maxCandidateNum); 47 | 48 | // counter related interfaces 49 | public static native CounterResult makeCounterSecret(); 50 | public static native CounterResult makeCounterParametersShare(String counterID, String counterSecret); 51 | public static native CounterResult count(String counterID, String counterSecret, String encryptedVoteSum); 52 | public static native CounterResult countUnlisted(String counterID, String counterSecret, String encryptedVoteSum); 53 | 54 | // verifier related interfaces 55 | public static native VerifierResult verifyVoteRequest(String pollParameters, String voteRequest, byte[] publicKey); 56 | public static native VerifierResult verifyUnboundedVoteRequest(String pollParameters, String voteRequest, byte[] publicKey); 57 | public static native VerifierResult verifyUnboundedVoteRequestUnlisted(String pollParameters, String voteRequest, byte[] publicKey); 58 | public static native VerifierResult verifyCountRequest(String pollParameter, String encryptedVoteSum, byte[] counterShared, String partiallyDecryptedResult); 59 | public static native VerifierResult verifyCountRequestUnlisted(String pollParameter, String encryptedVoteSum, byte[] counterShared, String partiallyDecryptedResult); 60 | public static native VerifierResult verifyVoteResult(String pollParameters, String voteSum, String aggregatedDecryptedResult, String voteResult); 61 | public static native VerifierResult verifyBlankBallot(String registrationRequest, String registrationResponse); 62 | 63 | // voter related interfaces 64 | public static native VoterResult makeVoterSecret(); 65 | public static native VoterResult generateRegistrationBlindingPoint(String voteSecret, String pollParameters); 66 | public static native VoterResult makeUnboundedRegistrationRequest(String zeroSecret, String voteSecret, String pollParameters); 67 | public static native VoterResult vote(String voteSecret, String voteChoices, String registrationResponse, String pollParameters); 68 | public static native VoterResult voteUnbounded(String voteSecret, String zeroSecret, String voteChoices, String registrationResponse, String pollParameters); 69 | public static native VoterResult voteUnboundedUnlisted(String voteSecret, String zeroSecret, String voteChoices, String registrationResponse, String pollParameters); 70 | } -------------------------------------------------------------------------------- /sdk-acv/src/main/java/com/webank/wedpr/acv/VerifierResult.java: -------------------------------------------------------------------------------- 1 | // Copyright 2022 WeDPR Lab Project Authors. Licensed under Apache-2.0. 2 | 3 | package com.webank.wedpr.acv; 4 | 5 | import com.webank.wedpr.common.WedprException; 6 | import com.webank.wedpr.common.WedprResult; 7 | 8 | /** 9 | * Result class used by VCL client. 10 | * 11 | *

This is an easy way to return multiple data from a single JNI interface. 12 | */ 13 | public class VerifierResult extends WedprResult { 14 | public boolean verifyResult; 15 | 16 | /** Expects no error occurred, otherwise throws an Exception. */ 17 | public VerifierResult expectNoError() throws WedprException { 18 | if (hasError()) { 19 | throw new WedprException(wedprErrorMessage); 20 | } 21 | return this; 22 | } 23 | 24 | public boolean isVerifyResult() { 25 | return verifyResult; 26 | } 27 | 28 | public void setVerifyResult(boolean verifyResult) { 29 | this.verifyResult = verifyResult; 30 | } 31 | } -------------------------------------------------------------------------------- /sdk-acv/src/main/java/com/webank/wedpr/acv/VoterResult.java: -------------------------------------------------------------------------------- 1 | // Copyright 2022 WeDPR Lab Project Authors. Licensed under Apache-2.0. 2 | 3 | package com.webank.wedpr.acv; 4 | 5 | import com.webank.wedpr.common.WedprException; 6 | import com.webank.wedpr.common.WedprResult; 7 | 8 | /** 9 | * Result class used by VCL client. 10 | * 11 | *

This is an easy way to return multiple data from a single JNI interface. 12 | */ 13 | public class VoterResult extends WedprResult { 14 | public String voter_secret; 15 | public String registration_blinding_point; 16 | public String registration_request; 17 | public String vote_request; 18 | 19 | /** Expects no error occurred, otherwise throws an Exception. */ 20 | public VoterResult expectNoError() throws WedprException { 21 | if (hasError()) { 22 | throw new WedprException(wedprErrorMessage); 23 | } 24 | return this; 25 | } 26 | } -------------------------------------------------------------------------------- /sdk-acv/src/main/java/com/webank/wedpr/acv/utils/PollParametersUtil.java: -------------------------------------------------------------------------------- 1 | package com.webank.wedpr.acv.utils; 2 | 3 | import com.google.protobuf.ByteString; 4 | import com.webank.wedpr.acv.proto.CandidateList; 5 | import com.webank.wedpr.acv.proto.PollParametersStorage; 6 | import com.webank.wedpr.common.Utils; 7 | 8 | import java.util.List; 9 | 10 | public class PollParametersUtil 11 | { 12 | public static PollParametersStorage makePollParameters(byte[] pollPoint, List candidateList) 13 | { 14 | PollParametersStorage.Builder builder = PollParametersStorage.newBuilder(); 15 | builder.setPollPoint(ByteString.copyFrom(pollPoint)); 16 | 17 | CandidateList.Builder candidateListBuilder = CandidateList.newBuilder(); 18 | for(int i = 0; i < candidateList.size(); i++) 19 | { 20 | candidateListBuilder.addCandidate(candidateList.get(i)); 21 | } 22 | builder.setCandidates(candidateListBuilder.build()); 23 | return builder.build(); 24 | } 25 | 26 | public static String makeStringPollParameters(byte[] pollPoint, List candidateList) 27 | { 28 | PollParametersStorage pollParametersStorage = makePollParameters(pollPoint, candidateList); 29 | return Utils.bytesToString(pollParametersStorage.toByteArray()); 30 | } 31 | } -------------------------------------------------------------------------------- /sdk-acv/src/main/proto/acv.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2021 WeDPR Lab Project Authors. Licensed under Apache-2.0. 2 | 3 | syntax = "proto3"; 4 | 5 | package com.webank.wedpr.acv.proto; 6 | option java_package = "com.webank.wedpr.acv.proto"; 7 | option java_multiple_files = true; 8 | 9 | // Candidate list. 10 | message CandidateList { 11 | repeated string candidate = 1; 12 | } 13 | 14 | // Shared system parameters to initialize a poll. 15 | message PollParametersStorage { 16 | bytes poll_point = 1; 17 | CandidateList candidates = 2; 18 | } 19 | 20 | // Secret of a counter. 21 | message CounterSecret { 22 | bytes poll_secret_share = 1; 23 | } 24 | 25 | // Secret of a voter. 26 | message VoterSecret { 27 | bytes voter_secret = 1; 28 | } 29 | 30 | // Request of registering a voter. 31 | message RegistrationRequest { 32 | RegistrationBlindingPoint weight_point = 1; 33 | // In a restricted voting scenario, the voting weight must be 0 or weight 34 | RegistrationBlindingPoint zero_point = 2; 35 | } 36 | 37 | // Blinding points for a voter registration. 38 | message RegistrationBlindingPoint { 39 | bytes blinding_poll_point = 1; 40 | bytes blinding_basepoint_g2 = 2; 41 | } 42 | 43 | // Response of voter registration. 44 | message RegistrationResponse { 45 | uint32 voter_weight = 1; 46 | Ballot ballot = 2; 47 | bytes signature = 3; 48 | Ballot zero_ballot = 4; 49 | } 50 | 51 | // Ciphertext ballot. 52 | message Ballot { 53 | bytes ciphertext1 = 1; 54 | bytes ciphertext2 = 2; 55 | } 56 | 57 | // Request of aggregating a part of system parameters from a counter. 58 | message CounterParametersShareRequest { 59 | string counter_id = 1; 60 | bytes poll_point_share = 2; 61 | } 62 | 63 | // Shared system parameters to initialize a group of counters. 64 | message CounterParametersStorage { 65 | repeated CounterParametersShareRequest counter_parameters_share = 1; 66 | } 67 | 68 | // Vote choice for a candidate. 69 | message VoteChoice { 70 | string candidate = 1; 71 | uint32 value = 2; 72 | } 73 | 74 | // pick other candidates from outside the given candidate list 75 | message UnlistedVoteChoice 76 | { 77 | // the unlisted candidate id 78 | uint32 candidate_id = 1; 79 | // the vote weight 80 | uint32 value = 2; 81 | } 82 | 83 | // Choice list for all candidates. 84 | message VoteChoices { 85 | repeated VoteChoice choice = 1; 86 | // Choose unlisted candidates 87 | repeated UnlistedVoteChoice unlisted_choice = 2; 88 | } 89 | 90 | // Ciphertext ballot for a candidate. 91 | message CandidateBallot { 92 | string candidate = 1; 93 | Ballot ballot = 2; 94 | } 95 | 96 | // ZKP data to verify the format of ciphertext ballot. 97 | message BallotProof { 98 | bytes format_proof = 1; 99 | // proof for unbounded vote scenes 100 | bytes either_equality_proof = 2; 101 | } 102 | 103 | // Pair of string (candidate id) and BallotProof. 104 | message StringToBallotProofPair { 105 | string key = 1; 106 | BallotProof value = 2; 107 | } 108 | 109 | // Request of voting for all candidates. 110 | message VoteRequest { 111 | VoteStorage vote = 1; 112 | repeated StringToBallotProofPair ballot_proof = 2; 113 | bytes range_proof = 3; 114 | bytes sum_balance_proof = 4; 115 | // the ballot proof for unlisted-candidates 116 | repeated CipherPointsToBallotProofPair unlisted_ballot_proof = 5; 117 | } 118 | 119 | // Ciphertext ballot for all candidates. 120 | message VoteStorage { 121 | bytes signature = 1; 122 | Ballot blank_ballot = 2; 123 | Ballot rest_ballot = 3; 124 | repeated CandidateBallot voted_ballot = 4; 125 | // the ballot for unlisted-candidates 126 | repeated CipherPointsToBallotPair voted_ballot_unlisted = 5; 127 | Ballot zero_ballot = 6; 128 | } 129 | 130 | // the ballot for the unlisted-candidate 131 | message CipherPointsToBallotPair 132 | { 133 | // the unlisted-candidate cipher 134 | CipherPoints key = 1; 135 | // the ballot for the unlisted-candidate 136 | Ballot ballot = 2; 137 | } 138 | 139 | // CipherPointsToBallotPair and CipherPointsToBallotProofPair associated by candidate cipher(CipherPoints) 140 | message CipherPointsToBallotProofPair { 141 | // the unlisted-candidate cipher 142 | CipherPoints key = 1; 143 | // the ballot proof for given ulisted-candidate 144 | BallotProof value = 2; 145 | } 146 | 147 | // the cipher for the unlisted-candidate 148 | message CipherPoints { 149 | bytes ciphertext1 = 1; 150 | bytes ciphertext2 = 2; 151 | } 152 | 153 | // Partially decrypted ballot and associated ZKP data for a candidate. 154 | message CountingPart { 155 | string counter_id = 1; 156 | bytes blinding_c2 = 2; 157 | bytes equality_proof = 3; 158 | } 159 | 160 | // Pair of string (candidate id) and CountingPart. 161 | message StringToCountingPartPair { 162 | string key = 1; 163 | CountingPart value = 2; 164 | } 165 | 166 | // Partially decrypted ballots and associated ZKP data for a poll. 167 | message DecryptedResultPartStorage { 168 | CountingPart blank_part = 1; 169 | repeated StringToCountingPartPair candidate_part = 2; 170 | // the decrypted part for the unlisted-candidate 171 | repeated UnlistedBallotDecryptedResult unlisted_candidate_part = 3; 172 | } 173 | 174 | // the decrypted result for the unlisted-candidate 175 | message UnlistedBallotDecryptedResult 176 | { 177 | // the unlisted candidate id 178 | int64 candidate = 1; 179 | CipherPoints candidate_cipher = 2; 180 | // the decrypted unlisted candidate 181 | CountingPart decrypted_unlisted_candidate = 4; 182 | // the decrypted unlisted candidate ballot 183 | // here use vector for aggregate_decrypted_part_sum_unlisted 184 | repeated CountingPart decrypted_unlisted_candidate_ballot = 5; 185 | } 186 | 187 | // Fully decrypted result of a poll. 188 | message VoteResultStorage { 189 | // the vote result for candidate list 190 | repeated StringToInt64Pair result = 1; 191 | // the vote result for the unlisted candidate list 192 | repeated UnlistedVoteChoice unlisted_result = 2; 193 | } 194 | 195 | // Pair of string (candidate id) and number. 196 | message StringToInt64Pair { 197 | string key = 1; 198 | int64 value = 2; 199 | } 200 | -------------------------------------------------------------------------------- /sdk-common/build.gradle: -------------------------------------------------------------------------------- 1 | // Apply the java-library plugin to add support for Java Library 2 | plugins { 3 | id 'java' 4 | } 5 | task sourcesJar(type: Jar) { 6 | from sourceSets.main.allJava 7 | archiveClassifier = 'sources' 8 | } 9 | 10 | task javadocJar(type: Jar) { 11 | from javadoc 12 | archiveClassifier = 'javadoc' 13 | } 14 | publishing { 15 | publications { 16 | mavenJava(MavenPublication) { 17 | 18 | artifactId "WeDPR-Lab-" + project.name 19 | groupId project.group 20 | version project.version 21 | 22 | from components.java 23 | artifact sourcesJar 24 | artifact javadocJar 25 | pom { 26 | name = 'WeDPR-Lab-Java-SDK' 27 | description = 'WeDPR-Lab-Java-SDK' 28 | url = 'http://www.fisco-bcos.org' 29 | 30 | licenses { 31 | license { 32 | name = 'The Apache License, Version 2.0' 33 | url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' 34 | } 35 | } 36 | developers { 37 | developer { 38 | id = 'zhangsan' 39 | name = 'zhangsan' 40 | email = 'zhangsan@example.com' 41 | } 42 | } 43 | scm { 44 | connection = 'https://github.com/WeBankBlockchain/WeDPR-Lab-Java-SDK' 45 | url = 'https://github.com/WeBankBlockchain/WeDPR-Lab-Java-SDK' 46 | } 47 | } 48 | } 49 | } 50 | repositories { 51 | maven { 52 | def releasesRepoURL = "https://oss.sonatype.org/service/local/staging/deploy/maven2" 53 | def snapshotsRepoURL = "https://oss.sonatype.org/content/repositories/snapshots" 54 | url = !version.endsWith("SNAPSHOT") ? releasesRepoURL : snapshotsRepoURL 55 | 56 | credentials { 57 | username ossrhUsername 58 | password ossrhPassword 59 | } 60 | } 61 | } 62 | 63 | signing { 64 | sign publishing.publications.mavenJava 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /sdk-common/src/main/java/com/webank/wedpr/common/NativeUtils.java: -------------------------------------------------------------------------------- 1 | package com.webank.wedpr.common; 2 | 3 | import java.io.File; 4 | import java.io.FileOutputStream; 5 | import java.io.IOException; 6 | import java.io.InputStream; 7 | import java.nio.channels.FileChannel; 8 | import java.nio.channels.FileLock; 9 | import java.nio.file.*; 10 | 11 | /** 12 | * load native resource 13 | * 14 | * @author aaronchu @Description 15 | */ 16 | public class NativeUtils { 17 | 18 | public static void loadLibrary(String resourcePath) throws IOException { 19 | ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); 20 | loadLibrary(resourcePath, classLoader); 21 | } 22 | 23 | public static boolean loadLibraryFromLibraryPath(String libraryDirPath, String resourcePath) 24 | throws IOException { 25 | String fileName = deduceFileName(resourcePath); 26 | File libraryFilePath = new File(new File(libraryDirPath), fileName); 27 | if (!libraryFilePath.exists() || !new File(libraryDirPath).exists()) { 28 | return false; 29 | } 30 | System.load(libraryFilePath.getAbsolutePath()); 31 | return true; 32 | } 33 | 34 | public static void loadLibrary(String resourcePath, ClassLoader classLoader) 35 | throws IOException { 36 | String libraryDirPath = System.getProperty("java.library.ffipath"); 37 | // load the library from the libraryPath 38 | if (libraryDirPath != null && !libraryDirPath.isEmpty()) { 39 | if (loadLibraryFromLibraryPath(libraryDirPath, resourcePath)) { 40 | return; 41 | } 42 | } 43 | 44 | File tmpDir = new File(System.getProperty("user.home")); 45 | if (!tmpDir.exists() || !tmpDir.isDirectory()) { 46 | throw new IOException("user dir unavailable"); 47 | } 48 | File ffiDir = new File(new File(tmpDir, ".fisco"), "nativeutils"); 49 | 50 | if (!ffiDir.exists() || !ffiDir.isDirectory()) { 51 | if (!ffiDir.mkdirs()) { 52 | throw new IOException("failed to create temp folder"); 53 | } 54 | } 55 | 56 | String fileName = deduceFileName(resourcePath); 57 | File tmpFile = new File(ffiDir, fileName); 58 | 59 | // To make sure write and load is atomic, incase p1 writes fails p2 load 60 | File lockFile = new File(ffiDir, "native.lock"); 61 | lockFile.deleteOnExit(); 62 | FileLock lock = null; 63 | try (FileChannel c = new FileOutputStream(lockFile, true).getChannel()) { 64 | lock = c.lock(); 65 | 66 | try (InputStream input = classLoader.getResourceAsStream(resourcePath); ) { 67 | if (input == null) { 68 | throw new IOException( 69 | "Resource not found:" 70 | + resourcePath 71 | + " for classloader " 72 | + classLoader.toString()); 73 | } 74 | Files.copy(input, tmpFile.toPath(), StandardCopyOption.REPLACE_EXISTING); 75 | } catch (AccessDeniedException e) { 76 | // In case that p1 load fails p2 write 77 | } 78 | 79 | System.load(tmpFile.getAbsolutePath()); 80 | } finally { 81 | if (lock != null) { 82 | try { 83 | lock.release(); 84 | lockFile.delete(); 85 | } catch (Exception e) { 86 | } 87 | } 88 | } 89 | } 90 | 91 | private static String deduceFileName(String path) { 92 | String[] parts = path.split("/"); 93 | if (parts.length > 0) { 94 | return parts[parts.length - 1]; 95 | } 96 | throw new IllegalArgumentException("invalid path " + path); 97 | } 98 | 99 | private NativeUtils() {} 100 | } 101 | -------------------------------------------------------------------------------- /sdk-common/src/main/java/com/webank/wedpr/common/Utils.java: -------------------------------------------------------------------------------- 1 | package com.webank.wedpr.common; 2 | 3 | import java.util.*; 4 | 5 | public class Utils { 6 | 7 | public static String bytesToString(byte[] param) { 8 | return Base64.getEncoder().encodeToString(param); 9 | } 10 | 11 | public static byte[] stringToBytes(String param) { 12 | return Base64.getDecoder().decode(param); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /sdk-common/src/main/java/com/webank/wedpr/common/WedprException.java: -------------------------------------------------------------------------------- 1 | // Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. 2 | 3 | package com.webank.wedpr.common; 4 | 5 | /** Base exception class used by WeDPR Java SDK. */ 6 | public class WedprException extends Exception { 7 | 8 | public WedprException() { 9 | super(); 10 | } 11 | 12 | public WedprException(String message) { 13 | super(message); 14 | } 15 | 16 | public WedprException(Throwable cause) { 17 | super(cause); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /sdk-common/src/main/java/com/webank/wedpr/common/WedprResult.java: -------------------------------------------------------------------------------- 1 | // Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. 2 | 3 | package com.webank.wedpr.common; 4 | 5 | /** Base result class used by WeDPR Java SDK. */ 6 | public class WedprResult { 7 | public String wedprErrorMessage; 8 | 9 | /** Checks whether any error occurred. */ 10 | public boolean hasError() { 11 | return wedprErrorMessage != null; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /sdk-crypto/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | } 4 | dependencies { 5 | api project(':sdk-common') 6 | implementation project(':sdk-common') 7 | } 8 | task sourcesJar(type: Jar) { 9 | from sourceSets.main.allJava 10 | archiveClassifier = 'sources' 11 | } 12 | 13 | task javadocJar(type: Jar) { 14 | from javadoc 15 | archiveClassifier = 'javadoc' 16 | } 17 | -------------------------------------------------------------------------------- /sdk-crypto/src/main/java/com/webank/wedpr/crypto/CryptoClient.java: -------------------------------------------------------------------------------- 1 | // Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. 2 | package com.webank.wedpr.crypto; 3 | 4 | import com.webank.wedpr.common.WedprException; 5 | 6 | /** 7 | * Client class used by crypto tools. This is the main interface class for Java apps using crypto 8 | * functions. 9 | */ 10 | public class CryptoClient { 11 | 12 | /** 13 | * Encrypts an encoded message by ECIES with a public key on the secp256k1 curve. 14 | * 15 | * @param publicKey encoded public key. 16 | * @param message encoded message to encrypt. 17 | * @return CryptoResult containing data for encryptedData. 18 | * @throws WedprException if any error occurred. 19 | */ 20 | public CryptoResult secp256k1EciesEncrypt(String publicKey, String message) 21 | throws WedprException { 22 | return NativeInterface.secp256k1EciesEncrypt(publicKey, message).expectNoError(); 23 | } 24 | 25 | /** 26 | * Decrypts an encoded encryptedData by ECIES with a private key on the secp256k1 curve. 27 | * 28 | * @param privateKey encoded private key. 29 | * @param encryptedData encoded ciphertext to decrypt. 30 | * @return CryptoResult containing data for decryptedData. 31 | * @throws WedprException if any error occurred. 32 | */ 33 | public CryptoResult secp256k1EciesDecrypt(String privateKey, String encryptedData) 34 | throws WedprException { 35 | return NativeInterface.secp256k1EciesDecrypt(privateKey, encryptedData).expectNoError(); 36 | } 37 | 38 | /** 39 | * Generates a new key pair for signature algorithm on the secp256k1 curve. 40 | * 41 | * @return CryptoResult containing data for publicKey, privateKey. 42 | * @throws WedprException if any error occurred. 43 | */ 44 | public CryptoResult secp256k1GenKeyPair() throws WedprException { 45 | return NativeInterface.secp256k1GenKeyPair().expectNoError(); 46 | } 47 | 48 | /** 49 | * Signs a message hash with the private key on the secp256k1 curve. 50 | * 51 | * @param privateKey encoded private key. 52 | * @param messageHash encoded hash of a message to sign. 53 | * @return CryptoResult containing data for signature. 54 | * @throws WedprException if any error occurred. 55 | */ 56 | public CryptoResult secp256k1Sign(String privateKey, String messageHash) throws WedprException { 57 | return NativeInterface.secp256k1Sign(privateKey, messageHash).expectNoError(); 58 | } 59 | 60 | /** 61 | * Verifies a message hash with the public key on the secp256k1 curve. 62 | * 63 | * @param publicKey encoded public key. 64 | * @param messageHash encoded hash of a message to verify. 65 | * @param signature encoded signature 66 | * @return CryptoResult containing data for booleanResult. 67 | * @throws WedprException if any error occurred. 68 | */ 69 | public CryptoResult secp256k1Verify(String publicKey, String messageHash, String signature) 70 | throws WedprException { 71 | return NativeInterface.secp256k1Verify(publicKey, messageHash, signature).expectNoError(); 72 | } 73 | 74 | /** 75 | * Generates a keccak256 hash string from a bytes array of any length. 76 | * 77 | * @param message 78 | * @return CryptoResult containing data for hash. 79 | * @throws WedprException if any error occurred. 80 | */ 81 | public CryptoResult keccak256Hash(String message) throws WedprException { 82 | return NativeInterface.keccak256Hash(message).expectNoError(); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /sdk-crypto/src/main/java/com/webank/wedpr/crypto/CryptoResult.java: -------------------------------------------------------------------------------- 1 | // Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. 2 | 3 | package com.webank.wedpr.crypto; 4 | 5 | import com.webank.wedpr.common.WedprException; 6 | import com.webank.wedpr.common.WedprResult; 7 | 8 | /** 9 | * Result class used by Crypto client. 10 | * 11 | *

This is an easy way to return multiple data from a single JNI interface. 12 | */ 13 | public class CryptoResult extends WedprResult { 14 | public String signature; 15 | public String publicKey; 16 | public String privateKey; 17 | public String hash; 18 | public boolean booleanResult; 19 | public String encryptedData; 20 | public String decryptedData; 21 | 22 | /** Expects no error occurred, otherwise throws an Exception. */ 23 | public CryptoResult expectNoError() throws WedprException { 24 | if (hasError()) { 25 | throw new WedprException(wedprErrorMessage); 26 | } 27 | return this; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /sdk-crypto/src/main/java/com/webank/wedpr/crypto/NativeInterface.java: -------------------------------------------------------------------------------- 1 | // Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. 2 | 3 | package com.webank.wedpr.crypto; 4 | 5 | import com.webank.wedpr.common.NativeUtils; 6 | import java.io.IOException; 7 | 8 | /** Native interface for Crypto client. */ 9 | public class NativeInterface { 10 | 11 | static { 12 | try { 13 | // Load the dynamic library of Crypto on different operating systems. 14 | String osName = System.getProperty("os.name").toLowerCase(); 15 | String libPathInJar; 16 | if (osName.contains("windows")) { 17 | libPathInJar = "WeDPR_dynamic_lib/ffi_java_crypto.dll"; 18 | } else if (osName.contains("linux")) { 19 | libPathInJar = "WeDPR_dynamic_lib/libffi_java_crypto.so"; 20 | } else if (osName.contains("mac")) { 21 | libPathInJar = "WeDPR_dynamic_lib/libffi_java_crypto.dylib"; 22 | } else { 23 | throw new IOException( 24 | String.format("Operating system %s is not supported.", osName)); 25 | } 26 | NativeUtils.loadLibrary(libPathInJar); 27 | } catch (IOException e) { 28 | // TODO: Provide more instructions on resolving dynamic library loading errors. 29 | throw new RuntimeException(e); 30 | } 31 | } 32 | 33 | // JNI function section. 34 | public static native CryptoResult secp256k1EciesEncrypt(String publicKey, String message); 35 | 36 | public static native CryptoResult secp256k1EciesDecrypt( 37 | String privateKey, String encryptedData); 38 | 39 | public static native CryptoResult secp256k1GenKeyPair(); 40 | 41 | public static native CryptoResult secp256k1Sign(String privateKey, String messageHash); 42 | 43 | public static native CryptoResult secp256k1Verify( 44 | String publicKey, String messageHash, String signature); 45 | 46 | public static native CryptoResult keccak256Hash(String message); 47 | } 48 | -------------------------------------------------------------------------------- /sdk-crypto/src/main/resources/WeDPR_dynamic_lib/.blank_file: -------------------------------------------------------------------------------- 1 | Have a good day :D 2 | -------------------------------------------------------------------------------- /sdk-demo/build.gradle: -------------------------------------------------------------------------------- 1 | // Apply the java-library plugin to add support for Java Library 2 | plugins { 3 | id 'java' 4 | } 5 | dependencies { 6 | api project(':sdk-common') 7 | implementation project(':sdk-common') 8 | api project(':sdk-crypto') 9 | implementation project(':sdk-crypto') 10 | api project(':sdk-ktb') 11 | implementation project(':sdk-ktb') 12 | api project(':sdk-scd') 13 | implementation project(':sdk-scd') 14 | api project(':sdk-vcl') 15 | implementation project(':sdk-vcl') 16 | implementation("com.google.protobuf:protobuf-java:${protobufVersion}") 17 | implementation("org.projectlombok:lombok:${lombokVersion}") 18 | } 19 | task sourcesJar(type: Jar) { 20 | from sourceSets.main.allJava 21 | archiveClassifier = 'sources' 22 | } 23 | 24 | task javadocJar(type: Jar) { 25 | from javadoc 26 | archiveClassifier = 'javadoc' 27 | } 28 | -------------------------------------------------------------------------------- /sdk-demo/src/main/java/com/webank/wedpr/demo/CryptoDemo.java: -------------------------------------------------------------------------------- 1 | // Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. 2 | 3 | package com.webank.wedpr.demo; 4 | 5 | import com.webank.wedpr.crypto.CryptoClient; 6 | import com.webank.wedpr.crypto.CryptoResult; 7 | import java.util.Base64; 8 | 9 | /** Minimalist demo of WeDPR Crypto Tools. */ 10 | public class CryptoDemo { 11 | public static void run(CryptoClient cryptoClient) throws Exception { 12 | System.out.println("\n*******\nCRYPTO DEMO RUN\n*******"); 13 | 14 | CryptoResult cryptoResult = cryptoClient.secp256k1GenKeyPair(); 15 | String publicKey = cryptoResult.publicKey; 16 | String privateKey = cryptoResult.privateKey; 17 | System.out.println("public key = " + publicKey); 18 | System.out.println("private key = " + privateKey); 19 | 20 | // Base64 encoding for "WeDPR Demo", which is currently required to pass bytes input to API. 21 | // TODO: Allow non-encoded UTF8 input. 22 | String message = Base64.getEncoder().encodeToString("WeDPR Demo".getBytes()); 23 | String messageHash = cryptoClient.keccak256Hash(message).hash; 24 | System.out.println("messageHash = " + messageHash); 25 | 26 | String signature = cryptoClient.secp256k1Sign(privateKey, messageHash).signature; 27 | System.out.println("signature = " + signature); 28 | 29 | boolean result = cryptoClient.secp256k1Verify(publicKey, messageHash, signature).booleanResult; 30 | System.out.println("signature verify result = " + result); 31 | 32 | String encryptedData = cryptoClient.secp256k1EciesEncrypt(publicKey, messageHash).encryptedData; 33 | System.out.println("encryptedData = " + encryptedData); 34 | 35 | String decryptedData = 36 | cryptoClient.secp256k1EciesDecrypt(privateKey, encryptedData).decryptedData; 37 | System.out.println("decryptedData = " + decryptedData); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /sdk-demo/src/main/java/com/webank/wedpr/demo/DemoMain.java: -------------------------------------------------------------------------------- 1 | // Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. 2 | 3 | package com.webank.wedpr.demo; 4 | 5 | import com.webank.wedpr.crypto.CryptoClient; 6 | import com.webank.wedpr.ktb.hdk.HdkClient; 7 | import com.webank.wedpr.scd.IssuerClient; 8 | import com.webank.wedpr.scd.UserClient; 9 | import com.webank.wedpr.scd.VerifierClient; 10 | import com.webank.wedpr.vcl.VclClient; 11 | 12 | /** Demo Launcher. */ 13 | public class DemoMain { 14 | 15 | public static void main(String[] args) throws Exception { 16 | CryptoClient cryptoClient = new CryptoClient(); 17 | CryptoDemo.run(cryptoClient); 18 | 19 | VclClient vclClient = new VclClient(); 20 | VclDemo.run(vclClient, 2, 2, 4); 21 | VclDemo.run(vclClient, 3, 4, 12); 22 | VclDemo.run(vclClient, 1, 2, 3); 23 | VclDemo.run(vclClient, 3, 4, 5); 24 | VclDemo.run(vclClient, -1, 4, 3); 25 | 26 | IssuerClient issuerClient = new IssuerClient(); 27 | UserClient userClient = new UserClient(); 28 | VerifierClient verifierClient = new VerifierClient(); 29 | ScdDemo.run(issuerClient, userClient, verifierClient); 30 | 31 | HdkClient hdkClient = new HdkClient(); 32 | KtbDemo.run(hdkClient); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /sdk-demo/src/main/java/com/webank/wedpr/demo/KtbDemo.java: -------------------------------------------------------------------------------- 1 | // Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. 2 | 3 | package com.webank.wedpr.demo; 4 | 5 | import com.webank.wedpr.ktb.hdk.HdkClient; 6 | import com.webank.wedpr.ktb.hdk.HdkResult; 7 | 8 | /** Minimalist demo of key tool box (KTB). */ 9 | public class KtbDemo { 10 | public static void run(HdkClient hdkClient) throws Exception { 11 | System.out.println("\n*******\nKTB DEMO RUN\n*******"); 12 | 13 | HdkResult hdkResult = hdkClient.createMnemonicEn(24); 14 | String mnemonic = hdkResult.mnemonic; 15 | System.out.println("mnemonic = " + mnemonic); 16 | 17 | String password = "Do not use real password"; 18 | hdkResult = hdkClient.createMasterKeyEn(password, mnemonic); 19 | String masterKey = hdkResult.masterKey; 20 | System.out.println("masterKey = " + masterKey); 21 | 22 | int purposeType = 44; 23 | int assetType = 513866; 24 | int account = 1; 25 | int change = 0; 26 | int addressIndex = 1000; 27 | hdkResult = 28 | hdkClient.deriveExtendedKey( 29 | masterKey, purposeType, assetType, account, change, addressIndex); 30 | String extendedPrivateKey = hdkResult.extendedPrivateKey; 31 | String extendedPublicKey = hdkResult.extendedPublicKey; 32 | System.out.println("extendedPrivateKey = " + extendedPrivateKey); 33 | System.out.println("extendedPublicKey = " + extendedPublicKey); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /sdk-demo/src/main/java/com/webank/wedpr/demo/ScdDemo.java: -------------------------------------------------------------------------------- 1 | // Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. 2 | 3 | package com.webank.wedpr.demo; 4 | 5 | import com.webank.wedpr.common.Utils; 6 | import com.webank.wedpr.scd.*; 7 | import com.webank.wedpr.scd.proto.*; 8 | import java.util.*; 9 | 10 | /** 11 | * Minimalist demo of selective certificate disclosure (SCD). 12 | * 13 | *

For a better interactive demo, please try our Rust version at 14 | * https://github.com/WeBankBlockchain/WeDPR-Lab-Core 15 | */ 16 | public class ScdDemo { 17 | private static final String NAME = "name"; 18 | private static final String AGE = "age"; 19 | private static final String GENDER = "gender"; 20 | private static final String ISSUE_TIME = "issue_time"; 21 | private static final String DEFAULT_USER_ID = "default_user_id"; 22 | 23 | public static void run( 24 | IssuerClient issuerClient, UserClient userClient, VerifierClient verifierClient) 25 | throws Exception { 26 | System.out.println("\n*******\nSCD DEMO RUN\n*******"); 27 | 28 | // An issuer defines the certificate schema and generates the certificate template. 29 | List schema = Arrays.asList(NAME, AGE, GENDER, ISSUE_TIME); 30 | System.out.println("Encoded schema = " + schema); 31 | 32 | IssuerResult issuerResult = issuerClient.makeCertificateTemplate(schema); 33 | 34 | String certificateTemplate = issuerResult.certificateTemplate; 35 | String templatePrivateKey = issuerResult.templatePrivateKey; 36 | System.out.println("Encoded certificateTemplate = " + certificateTemplate); 37 | System.out.println("Encoded templatePrivateKey = " + templatePrivateKey); 38 | 39 | // A user fills the certificate template and prepares a request for the issuer to sign. 40 | Map certificateDataInput = new HashMap<>(); 41 | // TODO: Add a utility function to convert any string to a decimal string. 42 | // Before this utility function is implemented, the attribute value can only be a decimal 43 | // string. 44 | certificateDataInput.put(NAME, "123"); 45 | certificateDataInput.put(AGE, "19"); 46 | certificateDataInput.put(GENDER, "1"); 47 | certificateDataInput.put(ISSUE_TIME, "12345"); 48 | String certificateData = userClient.encodeAttributeDict(certificateDataInput); 49 | UserResult userResult = userClient.fillCertificate(certificateData, certificateTemplate); 50 | 51 | String signCertificateRequest = userResult.signCertificateRequest; 52 | String userPrivateKey = userResult.userPrivateKey; 53 | String certificateSecretsBlindingFactors = userResult.certificateSecretsBlindingFactors; 54 | String userNonce = userResult.userNonce; 55 | System.out.println("Encoded signCertificateRequest = " + signCertificateRequest); 56 | System.out.println("Encoded userPrivateKey = " + userPrivateKey); 57 | System.out.println( 58 | "Encoded certificateSecretsBlindingFactors = " + certificateSecretsBlindingFactors); 59 | System.out.println("Encoded userNonce = " + userNonce); 60 | 61 | // The issuer verifies the certificate signing request from the user and signs the certificate. 62 | issuerResult = 63 | issuerClient.signCertificate( 64 | certificateTemplate, 65 | templatePrivateKey, 66 | signCertificateRequest, 67 | DEFAULT_USER_ID, 68 | userNonce); 69 | 70 | String certificateSignature = issuerResult.certificateSignature; 71 | String issuerNonce = issuerResult.issuerNonce; 72 | System.out.println("Encoded certificateSignature = " + certificateSignature); 73 | System.out.println("Encoded issuerNonce = " + issuerNonce); 74 | 75 | // The user blinds the received certificateSignature to prevent the issuer to track the 76 | // certificate usage. 77 | userResult = 78 | userClient.blindCertificateSignature( 79 | certificateSignature, 80 | certificateData, 81 | certificateTemplate, 82 | userPrivateKey, 83 | certificateSecretsBlindingFactors, 84 | issuerNonce); 85 | 86 | String blindedCertificateSignature = userResult.certificateSignature; 87 | System.out.println("Encoded blindedCertificateSignature = " + blindedCertificateSignature); 88 | 89 | // A verifier sets a verification rule to: 90 | // Check AGE > 18 and, 91 | VerificationRuleSet.Builder verificationRuleSetBuilder = VerificationRuleSet.newBuilder(); 92 | Predicate predicate = 93 | Predicate.newBuilder() 94 | .setAttributeName(AGE) 95 | .setPredicateType(PredicateType.GT.name()) 96 | .setPredicateValue(18) 97 | .build(); 98 | verificationRuleSetBuilder.addAttributePredicate(predicate); 99 | // Reveal the ISSUE_TIME attribute. 100 | verificationRuleSetBuilder.addRevealedAttributeName(ISSUE_TIME); 101 | 102 | String encodedVerificationRuleSet = 103 | verifierClient.protoToEncodedString(verificationRuleSetBuilder.build()); 104 | System.out.println("Encoded verificationRuleSet = " + encodedVerificationRuleSet); 105 | 106 | String verificationNonce = verifierClient.getVerificationNonce().verificationNonce; 107 | 108 | // The user proves the signed certificate data satisfying the verification rules and does not 109 | // reveal any extra data. 110 | userResult = 111 | userClient.proveSelectiveDisclosure( 112 | encodedVerificationRuleSet, 113 | blindedCertificateSignature, 114 | certificateData, 115 | certificateTemplate, 116 | userPrivateKey, 117 | verificationNonce); 118 | 119 | String verifyRequest = userResult.verifyRequest; 120 | System.out.println("Encoded verifyRequest = " + verifyRequest); 121 | 122 | // The verifier verifies the required verification rule is satisfied and extracts the required 123 | // attribute. 124 | // This verification should be done before calling revealedAttributeDict. 125 | VerifierResult verifierResult = 126 | verifierClient.verifySelectiveDisclosure(encodedVerificationRuleSet, verifyRequest); 127 | System.out.println("Proof verification result = " + verifierResult.boolResult); 128 | 129 | verifierResult = verifierClient.getRevealedAttributes(verifyRequest); 130 | String encodedRevealedCertificateData = verifierResult.revealedAttributeDict; 131 | AttributeDict revealedCertificateData = 132 | AttributeDict.parseFrom(Utils.stringToBytes(encodedRevealedCertificateData)); 133 | System.out.println("revealedCertificateData =" + revealedCertificateData); 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /sdk-demo/src/main/java/com/webank/wedpr/demo/VclDemo.java: -------------------------------------------------------------------------------- 1 | // Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. 2 | 3 | package com.webank.wedpr.demo; 4 | 5 | import com.webank.wedpr.vcl.VclClient; 6 | import com.webank.wedpr.vcl.VclResult; 7 | 8 | /** 9 | * Minimalist demo of verifiable confidential ledger (VCL). 10 | * 11 | *

For a better interactive demo, please try our Rust version at 12 | * https://github.com/WeBankBlockchain/WeDPR-Lab-Core 13 | */ 14 | public class VclDemo { 15 | public static void run(VclClient vclClient, long c1Value, long c2Value, long c3Value) 16 | throws Exception { 17 | System.out.println("\n*******\nVCL DEMO RUN\n*******"); 18 | System.out.println( 19 | "c1_value = " + c1Value + ", c2_value = " + c2Value + ", c3_value = " + c3Value + "\n"); 20 | 21 | if (c1Value < 0 || c2Value < 0 || c3Value < 0) { 22 | System.out.println( 23 | "[WARNING] Non-positive value detected.\n" 24 | + "All the balance proofs (sum and product) will fail intentionally.\n"); 25 | } 26 | 27 | // Create confidential credit records for those values. 28 | VclResult c1Result = vclClient.makeCredit(c1Value); 29 | System.out.println("c1_credit (publicly verifiable) = " + c1Result.confidentialCredit); 30 | System.out.println("c1_secret (only known by the owner) = " + c1Result.ownerSecret); 31 | 32 | VclResult c2Result = vclClient.makeCredit(c2Value); 33 | System.out.println("c2_credit (publicly verifiable) = " + c2Result.confidentialCredit); 34 | System.out.println("c2_secret (only known by the owner) = " + c2Result.ownerSecret); 35 | 36 | VclResult c3Result = vclClient.makeCredit(c3Value); 37 | System.out.println("c3_credit (publicly verifiable) = " + c3Result.confidentialCredit); 38 | System.out.println("c3_secret (only known by the owner) = " + c3Result.ownerSecret); 39 | 40 | // Prove c1_value + c2_value = c3_value. 41 | VclResult sumResult = 42 | vclClient.proveSumBalance(c1Result.ownerSecret, c2Result.ownerSecret, c3Result.ownerSecret); 43 | System.out.println( 44 | "\nproof of " + c1Value + " + " + c2Value + " =? " + c3Value + ":\n" + sumResult.proof); 45 | 46 | VclResult verifySumResult = 47 | vclClient.verifySumBalance( 48 | c1Result.confidentialCredit, 49 | c2Result.confidentialCredit, 50 | c3Result.confidentialCredit, 51 | sumResult.proof); 52 | if (verifySumResult.verificationResult) { 53 | System.out.println(">> Pass: " + c1Value + " + " + c2Value + " == " + c3Value); 54 | } else { 55 | System.out.println("<< Fail: " + c1Value + " + " + c2Value + " != " + c3Value); 56 | } 57 | 58 | // Prove c1_value * c2_value = c3_value. 59 | VclResult productResult = 60 | vclClient.proveProductBalance( 61 | c1Result.ownerSecret, c2Result.ownerSecret, c3Result.ownerSecret); 62 | System.out.println( 63 | "\nproof of " + c1Value + " * " + c2Value + " =? " + c3Value + ":\n" + productResult.proof); 64 | 65 | VclResult verifyMultiResult = 66 | vclClient.verifyProductBalance( 67 | c1Result.confidentialCredit, 68 | c2Result.confidentialCredit, 69 | c3Result.confidentialCredit, 70 | productResult.proof); 71 | if (verifyMultiResult.verificationResult) { 72 | System.out.println(">> Pass: " + c1Value + " * " + c2Value + " == " + c3Value); 73 | } else { 74 | System.out.println("<< Fail: " + c1Value + " * " + c2Value + " != " + c3Value); 75 | } 76 | 77 | // Prove c1_value in [0, 2^32-1]. 78 | VclResult rangeResult = vclClient.proveRange(c1Result.ownerSecret); 79 | System.out.println("\nproof of " + c1Value + " in [0, 2^32-1]:\n" + productResult.proof); 80 | 81 | VclResult verifyRangeResult = 82 | vclClient.verifyRange(c1Result.confidentialCredit, rangeResult.proof); 83 | if (verifyRangeResult.verificationResult) { 84 | System.out.println(">> Pass: " + c1Value + " in [0, 2^32-1]"); 85 | } else { 86 | System.out.println("<< Fail: " + c1Value + " not in [0, 2^32-1]"); 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /sdk-demo/src/main/resources/WeDPR_dynamic_lib/.blank_file: -------------------------------------------------------------------------------- 1 | Have a good day :D 2 | -------------------------------------------------------------------------------- /sdk-ktb/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | } 4 | dependencies { 5 | api project(':sdk-common') 6 | implementation project(':sdk-common') 7 | } 8 | task sourcesJar(type: Jar) { 9 | from sourceSets.main.allJava 10 | archiveClassifier = 'sources' 11 | } 12 | 13 | task javadocJar(type: Jar) { 14 | from javadoc 15 | archiveClassifier = 'javadoc' 16 | } 17 | -------------------------------------------------------------------------------- /sdk-ktb/src/main/java/com/webank/wedpr/ktb/hdk/HdkClient.java: -------------------------------------------------------------------------------- 1 | // Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. 2 | 3 | package com.webank.wedpr.ktb.hdk; 4 | 5 | import com.webank.wedpr.common.WedprException; 6 | 7 | /** 8 | * Client class used by KTB-HDK. This is the main interface class for Java apps using HDK functions. 9 | */ 10 | public class HdkClient { 11 | 12 | /** 13 | * Creates an English mnemonic for later generating the master key. 14 | * 15 | * @param wordCount the word count of the mnemonic. 16 | * @return HdkResult containing data for mnemonic. 17 | * @throws WedprException if any error occurred. 18 | */ 19 | public HdkResult createMnemonicEn(int wordCount) throws WedprException { 20 | return NativeInterface.createMnemonicEn(wordCount).expectNoError(); 21 | } 22 | 23 | /** 24 | * Creates a master key from a English mnemonic and a password. 25 | * 26 | * @param password the password used together with the mnemonic. 27 | * @param mnemonic the mnemonic for master key recovery. 28 | * @return HdkResult containing data for masterKey. 29 | * @throws WedprException if any error occurred. 30 | */ 31 | public HdkResult createMasterKeyEn(String password, String mnemonic) throws WedprException { 32 | return NativeInterface.createMasterKeyEn(password, mnemonic).expectNoError(); 33 | } 34 | 35 | /** 36 | * Derives an extended key pair based on a key derivation path. 37 | * 38 | * @param masterKey the master key for key derivation. 39 | * @param purposeType the purpose type of the derived key. 40 | * @param assetType the asset subtype of the derived key. 41 | * @param account the account subtype of the derived key. 42 | * @param change the change subtype of the derived key. 43 | * @param addressIndex the address index of the derived key. 44 | * @return HdkResult containing data for extendedPublicKey, extendedPrivateKey. 45 | * @throws WedprException if any error occurred. 46 | */ 47 | public HdkResult deriveExtendedKey( 48 | String masterKey, 49 | int purposeType, 50 | int assetType, 51 | int account, 52 | int change, 53 | int addressIndex) 54 | throws WedprException { 55 | return NativeInterface.deriveExtendedKey( 56 | masterKey, purposeType, assetType, account, change, addressIndex) 57 | .expectNoError(); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /sdk-ktb/src/main/java/com/webank/wedpr/ktb/hdk/HdkResult.java: -------------------------------------------------------------------------------- 1 | // Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. 2 | 3 | package com.webank.wedpr.ktb.hdk; 4 | 5 | import com.webank.wedpr.common.WedprException; 6 | import com.webank.wedpr.common.WedprResult; 7 | 8 | /** 9 | * Result class used by HDK client. 10 | * 11 | *

This is an easy way to return multiple data from a single JNI interface. 12 | */ 13 | public class HdkResult extends WedprResult { 14 | public String mnemonic; 15 | public String masterKey; 16 | public String extendedPrivateKey; 17 | public String extendedPublicKey; 18 | 19 | /** Expects no error occurred, otherwise throws an Exception. */ 20 | public HdkResult expectNoError() throws WedprException { 21 | if (hasError()) { 22 | throw new WedprException(wedprErrorMessage); 23 | } 24 | return this; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /sdk-ktb/src/main/java/com/webank/wedpr/ktb/hdk/NativeInterface.java: -------------------------------------------------------------------------------- 1 | // Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. 2 | 3 | package com.webank.wedpr.ktb.hdk; 4 | 5 | import com.webank.wedpr.common.NativeUtils; 6 | import java.io.IOException; 7 | 8 | /** Native interface for HDK client. */ 9 | public class NativeInterface { 10 | 11 | static { 12 | try { 13 | // Load the dynamic library of HDK on different operating systems. 14 | String osName = System.getProperty("os.name").toLowerCase(); 15 | String libPathInJar; 16 | if (osName.contains("windows")) { 17 | libPathInJar = "WeDPR_dynamic_lib/ffi_java_ktb.dll"; 18 | } else if (osName.contains("linux")) { 19 | libPathInJar = "WeDPR_dynamic_lib/libffi_java_ktb.so"; 20 | } else if (osName.contains("mac")) { 21 | libPathInJar = "WeDPR_dynamic_lib/libffi_java_ktb.dylib"; 22 | } else { 23 | throw new IOException( 24 | String.format("Operating system %s is not supported.", osName)); 25 | } 26 | NativeUtils.loadLibrary(libPathInJar); 27 | } catch (IOException e) { 28 | // TODO: Provide more instructions on resolving dynamic library loading errors. 29 | throw new RuntimeException(e); 30 | } 31 | } 32 | 33 | // JNI function section. 34 | public static native HdkResult createMnemonicEn(int wordCount); 35 | 36 | public static native HdkResult createMasterKeyEn(String password, String mnemonic); 37 | 38 | public static native HdkResult deriveExtendedKey( 39 | String masterKey, 40 | int purposeType, 41 | int assetType, 42 | int account, 43 | int change, 44 | int addressIndex); 45 | } 46 | -------------------------------------------------------------------------------- /sdk-ktb/src/main/resources/WeDPR_dynamic_lib/.blank_file: -------------------------------------------------------------------------------- 1 | Have a good day :D 2 | -------------------------------------------------------------------------------- /sdk-scd/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | } 4 | dependencies { 5 | api project(':sdk-common') 6 | implementation project(':sdk-common') 7 | implementation("com.google.protobuf:protobuf-java:${protobufVersion}") 8 | implementation("org.projectlombok:lombok:${lombokVersion}") 9 | } 10 | task sourcesJar(type: Jar) { 11 | from sourceSets.main.allJava 12 | archiveClassifier = 'sources' 13 | } 14 | 15 | task javadocJar(type: Jar) { 16 | from javadoc 17 | archiveClassifier = 'javadoc' 18 | } 19 | -------------------------------------------------------------------------------- /sdk-scd/src/main/java/com/webank/wedpr/scd/IssuerClient.java: -------------------------------------------------------------------------------- 1 | // Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. 2 | 3 | package com.webank.wedpr.scd; 4 | 5 | import com.webank.wedpr.common.WedprException; 6 | import com.webank.wedpr.scd.proto.CertificateSchema; 7 | import java.util.List; 8 | 9 | /** 10 | * Client class used by a SCD certificate issuer. This is the main interface class for Java apps 11 | * using SCD functions. 12 | */ 13 | public class IssuerClient extends ScdClient { 14 | /** 15 | * Makes a certificate template for users to fill data. 16 | * 17 | * @param schema the schema defining the certificate attribute name list. 18 | * @return IssuerResult containing data for certificateTemplate, templatePrivateKey. 19 | * @throws WedprException if any error occurred. 20 | */ 21 | public IssuerResult makeCertificateTemplate(List schema) throws WedprException { 22 | return NativeInterface.issuerMakeCertificateTemplate( 23 | protoToEncodedString( 24 | CertificateSchema.newBuilder().addAllAttributeName(schema).build())) 25 | .expectNoError(); 26 | } 27 | 28 | /** 29 | * Signs a verified certificate from a user. 30 | * 31 | * @param certificateTemplate the encoded certificate template. 32 | * @param templatePrivateKey the encoded template private key. 33 | * @param signRequest the encoded certificate signing request from the user. 34 | * @param userId the encoded user id. 35 | * @param userNonce the encoded nonce from the user. 36 | * @return IssuerResult containing data for certificateSignature, issuerNonce. 37 | * @throws WedprException if any error occurred. 38 | */ 39 | public IssuerResult signCertificate( 40 | String certificateTemplate, 41 | String templatePrivateKey, 42 | String signRequest, 43 | String userId, 44 | String userNonce) 45 | throws WedprException { 46 | return NativeInterface.issuerSignCertificate( 47 | certificateTemplate, templatePrivateKey, signRequest, userId, userNonce) 48 | .expectNoError(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /sdk-scd/src/main/java/com/webank/wedpr/scd/IssuerResult.java: -------------------------------------------------------------------------------- 1 | // Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. 2 | 3 | package com.webank.wedpr.scd; 4 | 5 | import com.webank.wedpr.common.WedprException; 6 | import com.webank.wedpr.common.WedprResult; 7 | 8 | /** 9 | * Result class used by a SCD certificate issuer. 10 | * 11 | *

This is an easy way to return multiple data from a single JNI interface. 12 | */ 13 | public class IssuerResult extends WedprResult { 14 | public String certificateTemplate; 15 | public String templatePrivateKey; 16 | public String certificateSignature; 17 | public String issuerNonce; 18 | 19 | /** Expects no error occurred, otherwise throws an Exception. */ 20 | public IssuerResult expectNoError() throws WedprException { 21 | if (hasError()) { 22 | throw new WedprException(wedprErrorMessage); 23 | } 24 | return this; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /sdk-scd/src/main/java/com/webank/wedpr/scd/NativeInterface.java: -------------------------------------------------------------------------------- 1 | // Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. 2 | 3 | package com.webank.wedpr.scd; 4 | 5 | import com.webank.wedpr.common.NativeUtils; 6 | import com.webank.wedpr.common.WedprException; 7 | import java.io.BufferedReader; 8 | import java.io.IOException; 9 | import java.io.InputStream; 10 | import java.io.InputStreamReader; 11 | import java.io.UnsupportedEncodingException; 12 | 13 | /** Native interface for SCD client. */ 14 | public class NativeInterface { 15 | 16 | public static final String WEDPR_SCD_LIB_PATH; 17 | public static final String LIBSSL_1_1 = "libssl.so.1.1"; 18 | public static final String LIBSSL_1_0 = "libssl.so.10"; 19 | 20 | static { 21 | try { 22 | String osName = System.getProperty("os.name").toLowerCase(); 23 | if (osName.contains("windows")) { 24 | WEDPR_SCD_LIB_PATH = "WeDPR_dynamic_lib/ffi_java_scd.dll"; 25 | NativeUtils.loadLibrary("WeDPR_dynamic_lib/libeay32md.dll"); 26 | NativeUtils.loadLibrary("WeDPR_dynamic_lib/ssleay32md.dll"); 27 | } else if (osName.contains("linux")) { 28 | if (hasLibsslVersion(LIBSSL_1_0)) { 29 | WEDPR_SCD_LIB_PATH = "WeDPR_dynamic_lib/libffi_java_scd_libssl_1_0.so"; 30 | } else if (hasLibsslVersion(LIBSSL_1_1)) { 31 | WEDPR_SCD_LIB_PATH = "WeDPR_dynamic_lib/libffi_java_scd_libssl_1_1.so"; 32 | } else { 33 | throw new WedprException("Linux requires " + LIBSSL_1_1 + " or " + LIBSSL_1_0); 34 | } 35 | } else if (osName.contains("mac")) { 36 | WEDPR_SCD_LIB_PATH = "WeDPR_dynamic_lib/libffi_java_scd.dylib"; 37 | } else { 38 | throw new IOException( 39 | String.format("Operating system %s is not supported.", osName)); 40 | } 41 | NativeUtils.loadLibrary(WEDPR_SCD_LIB_PATH); 42 | } catch (IOException | WedprException e) { 43 | throw new RuntimeException(e); 44 | } 45 | } 46 | 47 | private static boolean hasLibsslVersion(String libsslVersion) 48 | throws IOException, UnsupportedEncodingException { 49 | Process process = Runtime.getRuntime().exec("locate " + libsslVersion); 50 | InputStream inputStream = process.getInputStream(); 51 | BufferedReader bufferedReader = 52 | new BufferedReader(new InputStreamReader(inputStream, "UTF-8")); 53 | String version = bufferedReader.readLine(); 54 | return version != null; 55 | } 56 | 57 | public static native IssuerResult issuerMakeCertificateTemplate(String schema); 58 | 59 | public static native IssuerResult issuerSignCertificate( 60 | String certificateTemplate, 61 | String templatePrivateKey, 62 | String signRequest, 63 | String userId, 64 | String userNonce); 65 | 66 | public static native UserResult userFillCertificate( 67 | String attributeDict, String certificateTemplate); 68 | 69 | public static native UserResult userBlindCertificateSignature( 70 | String certificateSignature, 71 | String attributeDict, 72 | String certificateTemplate, 73 | String userPrivateKey, 74 | String certificateSecretsBlindingFactors, 75 | String issuerNonce); 76 | 77 | public static native UserResult userProveSelectiveDisclosure( 78 | String ruleSet, 79 | String certificateSignature, 80 | String attributeDict, 81 | String certificateTemplate, 82 | String userPrivateKey, 83 | String verificationNonce); 84 | 85 | public static native VerifierResult verifierVerifySelectiveDisclosure( 86 | String ruleSet, String verifyRequest); 87 | 88 | public static native VerifierResult verifierGetRevealedAttributes(String verifyRequest); 89 | 90 | public static native VerifierResult verifierGetVerificationNonce(); 91 | } 92 | -------------------------------------------------------------------------------- /sdk-scd/src/main/java/com/webank/wedpr/scd/PredicateType.java: -------------------------------------------------------------------------------- 1 | // Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. 2 | 3 | package com.webank.wedpr.scd; 4 | 5 | /** Predicate types supported by SCD. */ 6 | public enum PredicateType { 7 | GE, // > 8 | LE, // < 9 | GT, // >= 10 | LT, // <= 11 | EQ // == 12 | } 13 | -------------------------------------------------------------------------------- /sdk-scd/src/main/java/com/webank/wedpr/scd/ScdClient.java: -------------------------------------------------------------------------------- 1 | // Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. 2 | 3 | package com.webank.wedpr.scd; 4 | 5 | import com.google.protobuf.Message; 6 | import com.webank.wedpr.common.Utils; 7 | import com.webank.wedpr.scd.proto.AttributeDict; 8 | import com.webank.wedpr.scd.proto.StringToStringPair; 9 | import java.util.Map; 10 | 11 | /** Base client class used by SCD. */ 12 | abstract class ScdClient { 13 | /** 14 | * Encodes a filled attribute KV map to a String. 15 | * 16 | * @param attributeDictInput the KV map containing the filled data of a certificate. 17 | * @return the encoded string for attributeDictInput. 18 | */ 19 | public String encodeAttributeDict(Map attributeDictInput) { 20 | AttributeDict attributeDict = AttributeDict.getDefaultInstance(); 21 | for (Map.Entry entry : attributeDictInput.entrySet()) { 22 | StringToStringPair pair = 23 | StringToStringPair.newBuilder() 24 | .setKey(entry.getKey()) 25 | .setValue(entry.getValue()) 26 | .build(); 27 | attributeDict = attributeDict.toBuilder().addPair(pair).build(); 28 | } 29 | return protoToEncodedString(attributeDict); 30 | } 31 | 32 | /** 33 | * Encodes a Protobuf object to a String. 34 | * 35 | * @param message the Protobuf object. 36 | * @return the encoded string of message. 37 | */ 38 | public String protoToEncodedString(Message message) { 39 | return Utils.bytesToString(message.toByteArray()); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /sdk-scd/src/main/java/com/webank/wedpr/scd/UserClient.java: -------------------------------------------------------------------------------- 1 | // Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. 2 | 3 | package com.webank.wedpr.scd; 4 | 5 | import com.webank.wedpr.common.WedprException; 6 | 7 | /** 8 | * Client class used by a SCD certificate user. This is the main interface class for Java apps using 9 | * SCD functions. 10 | */ 11 | public class UserClient extends ScdClient { 12 | /** 13 | * Fills a certificate and generates a SignCertificateRequest for an issuer to sign. 14 | * 15 | * @param attributeDict the encode KV map for the filled data of a certificate. 16 | * @param certificateTemplate the encoded certificate template. 17 | * @return UserResult containing data for signCertificateRequest, userPrivateKey, 18 | * certificateSecretsBlindingFactors, userNonce. 19 | * @throws WedprException if any error occurred. 20 | */ 21 | public UserResult fillCertificate(String attributeDict, String certificateTemplate) 22 | throws WedprException { 23 | return NativeInterface.userFillCertificate(attributeDict, certificateTemplate) 24 | .expectNoError(); 25 | } 26 | 27 | /** 28 | * Blinds the signature of a signed certificate to prevent the issuer from tracking its usage. 29 | * 30 | * @param certificateSignature the encoded certificate signature signed by the issuer. 31 | * @param attributeDict the encode KV map for the filled data of a certificate. 32 | * @param certificateTemplate the encoded certificate template. 33 | * @param userPrivateKey the encoded user private key. 34 | * @param certificateSecretsBlindingFactors the encoded blinding factors. 35 | * @param issuerNonce the encoded nonce from the issuer. 36 | * @return UserResult containing data for certificateSignature. 37 | * @throws WedprException if any error occurred. 38 | */ 39 | public UserResult blindCertificateSignature( 40 | String certificateSignature, 41 | String attributeDict, 42 | String certificateTemplate, 43 | String userPrivateKey, 44 | String certificateSecretsBlindingFactors, 45 | String issuerNonce) 46 | throws WedprException { 47 | return NativeInterface.userBlindCertificateSignature( 48 | certificateSignature, 49 | attributeDict, 50 | certificateTemplate, 51 | userPrivateKey, 52 | certificateSecretsBlindingFactors, 53 | issuerNonce) 54 | .expectNoError(); 55 | } 56 | 57 | /** 58 | * Generate a VerifyRequest to prove the validity of selected attribute values and their value 59 | * predicates from a certificate, while those unselected attributes will not be revealed. 60 | * 61 | * @param ruleSet the encoded rule set for the disclosure from the verifier. 62 | * @param certificateSignature the encoded certificate signature. 63 | * @param attributeDict the encode KV map for the filled data of a certificate. 64 | * @param certificateTemplate the encoded certificate template. 65 | * @param userPrivateKey the encoded user private key. 66 | * @return UserResult containing data for verifyRequest. 67 | * @throws WedprException if any error occurred. 68 | */ 69 | public UserResult proveSelectiveDisclosure( 70 | String ruleSet, 71 | String certificateSignature, 72 | String attributeDict, 73 | String certificateTemplate, 74 | String userPrivateKey, 75 | String verificationNonce) 76 | throws WedprException { 77 | return NativeInterface.userProveSelectiveDisclosure( 78 | ruleSet, 79 | certificateSignature, 80 | attributeDict, 81 | certificateTemplate, 82 | userPrivateKey, 83 | verificationNonce) 84 | .expectNoError(); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /sdk-scd/src/main/java/com/webank/wedpr/scd/UserResult.java: -------------------------------------------------------------------------------- 1 | // Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. 2 | 3 | package com.webank.wedpr.scd; 4 | 5 | import com.webank.wedpr.common.WedprException; 6 | import com.webank.wedpr.common.WedprResult; 7 | 8 | /** 9 | * Result class used by a SCD certificate user. 10 | * 11 | *

This is an easy way to return multiple data from a single JNI interface. 12 | */ 13 | public class UserResult extends WedprResult { 14 | public String signCertificateRequest; 15 | public String userPrivateKey; 16 | public String certificateSecretsBlindingFactors; 17 | public String userNonce; 18 | public String certificateSignature; 19 | public String verifyRequest; 20 | 21 | /** Expects no error occurred, otherwise throws an Exception. */ 22 | public UserResult expectNoError() throws WedprException { 23 | if (hasError()) { 24 | throw new WedprException(wedprErrorMessage); 25 | } 26 | return this; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /sdk-scd/src/main/java/com/webank/wedpr/scd/VerifierClient.java: -------------------------------------------------------------------------------- 1 | // Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. 2 | 3 | package com.webank.wedpr.scd; 4 | 5 | import com.webank.wedpr.common.WedprException; 6 | 7 | /** 8 | * Client class used by a SCD certificate verifier. This is the main interface class for Java apps 9 | * using SCD functions. 10 | */ 11 | public class VerifierClient extends ScdClient { 12 | /** 13 | * Verifies the validity of a VerifyRequest containing selected attribute values and their value 14 | * predicates. 15 | * 16 | * @param ruleSet the encoded rule set for the disclosure. 17 | * @param verifyRequest the encoded disclosure verifying request from the user. 18 | * @return VerifierResult containing data for boolResult. 19 | * @throws WedprException if any error occurred. 20 | */ 21 | public VerifierResult verifySelectiveDisclosure(String ruleSet, String verifyRequest) 22 | throws WedprException { 23 | return NativeInterface.verifierVerifySelectiveDisclosure(ruleSet, verifyRequest) 24 | .expectNoError(); 25 | } 26 | 27 | /** 28 | * Gets revealed attributes selected by a user. Before calling this function, 29 | * verifySelectiveDisclosure should be called to verify the validity of the VerifyRequest. 30 | * 31 | * @param verifyRequest the encoded disclosure verifying request from the user. 32 | * @return VerifierResult containing data for revealedAttributeDict. 33 | * @throws WedprException if any error occurred. 34 | */ 35 | public VerifierResult getRevealedAttributes(String verifyRequest) throws WedprException { 36 | return NativeInterface.verifierGetRevealedAttributes(verifyRequest).expectNoError(); 37 | } 38 | 39 | /** 40 | * Generates a new encoded nonce as the challenge for a user to generate a fresh proof. 41 | * 42 | * @return VerifierResult containing data for verificationNonce. 43 | * @throws WedprException if any error occurred. 44 | */ 45 | public VerifierResult getVerificationNonce() throws WedprException { 46 | return NativeInterface.verifierGetVerificationNonce().expectNoError(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /sdk-scd/src/main/java/com/webank/wedpr/scd/VerifierResult.java: -------------------------------------------------------------------------------- 1 | // Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. 2 | 3 | package com.webank.wedpr.scd; 4 | 5 | import com.webank.wedpr.common.WedprException; 6 | import com.webank.wedpr.common.WedprResult; 7 | 8 | /** 9 | * Result class used by a SCD certificate verifier. 10 | * 11 | *

This is an easy way to return multiple data from a single JNI interface. 12 | */ 13 | public class VerifierResult extends WedprResult { 14 | public String revealedAttributeDict; 15 | public String verificationNonce; 16 | public boolean boolResult; 17 | 18 | /** Expects no error occurred, otherwise throws an Exception. */ 19 | public VerifierResult expectNoError() throws WedprException { 20 | if (hasError()) { 21 | throw new WedprException(wedprErrorMessage); 22 | } 23 | return this; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /sdk-scd/src/main/java/com/webank/wedpr/scd/proto/AttributeDictOrBuilder.java: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: scd.proto 3 | 4 | package com.webank.wedpr.scd.proto; 5 | 6 | public interface AttributeDictOrBuilder 7 | extends 8 | // @@protoc_insertion_point(interface_extends:com.webank.wedpr.scd.proto.AttributeDict) 9 | com.google.protobuf.MessageOrBuilder { 10 | 11 | /** repeated .com.webank.wedpr.scd.proto.StringToStringPair pair = 1; */ 12 | java.util.List getPairList(); 13 | /** repeated .com.webank.wedpr.scd.proto.StringToStringPair pair = 1; */ 14 | com.webank.wedpr.scd.proto.StringToStringPair getPair(int index); 15 | /** repeated .com.webank.wedpr.scd.proto.StringToStringPair pair = 1; */ 16 | int getPairCount(); 17 | /** repeated .com.webank.wedpr.scd.proto.StringToStringPair pair = 1; */ 18 | java.util.List 19 | getPairOrBuilderList(); 20 | /** repeated .com.webank.wedpr.scd.proto.StringToStringPair pair = 1; */ 21 | com.webank.wedpr.scd.proto.StringToStringPairOrBuilder getPairOrBuilder(int index); 22 | } 23 | -------------------------------------------------------------------------------- /sdk-scd/src/main/java/com/webank/wedpr/scd/proto/BlindedCertificateSecretOrBuilder.java: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: scd.proto 3 | 4 | package com.webank.wedpr.scd.proto; 5 | 6 | public interface BlindedCertificateSecretOrBuilder 7 | extends 8 | // @@protoc_insertion_point(interface_extends:com.webank.wedpr.scd.proto.BlindedCertificateSecret) 9 | com.google.protobuf.MessageOrBuilder { 10 | 11 | /** string blinded_certificate_secrets = 1; */ 12 | String getBlindedCertificateSecrets(); 13 | /** string blinded_certificate_secrets = 1; */ 14 | com.google.protobuf.ByteString getBlindedCertificateSecretsBytes(); 15 | 16 | /** string blinded_certificate_secrets_correctness_proof = 2; */ 17 | String getBlindedCertificateSecretsCorrectnessProof(); 18 | /** string blinded_certificate_secrets_correctness_proof = 2; */ 19 | com.google.protobuf.ByteString getBlindedCertificateSecretsCorrectnessProofBytes(); 20 | } 21 | -------------------------------------------------------------------------------- /sdk-scd/src/main/java/com/webank/wedpr/scd/proto/CertificateSchemaOrBuilder.java: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: scd.proto 3 | 4 | package com.webank.wedpr.scd.proto; 5 | 6 | public interface CertificateSchemaOrBuilder 7 | extends 8 | // @@protoc_insertion_point(interface_extends:com.webank.wedpr.scd.proto.CertificateSchema) 9 | com.google.protobuf.MessageOrBuilder { 10 | 11 | /** repeated string attribute_name = 1; */ 12 | java.util.List getAttributeNameList(); 13 | /** repeated string attribute_name = 1; */ 14 | int getAttributeNameCount(); 15 | /** repeated string attribute_name = 1; */ 16 | String getAttributeName(int index); 17 | /** repeated string attribute_name = 1; */ 18 | com.google.protobuf.ByteString getAttributeNameBytes(int index); 19 | } 20 | -------------------------------------------------------------------------------- /sdk-scd/src/main/java/com/webank/wedpr/scd/proto/CertificateSignatureOrBuilder.java: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: scd.proto 3 | 4 | package com.webank.wedpr.scd.proto; 5 | 6 | public interface CertificateSignatureOrBuilder 7 | extends 8 | // @@protoc_insertion_point(interface_extends:com.webank.wedpr.scd.proto.CertificateSignature) 9 | com.google.protobuf.MessageOrBuilder { 10 | 11 | /** string certificate_signature = 1; */ 12 | String getCertificateSignature(); 13 | /** string certificate_signature = 1; */ 14 | com.google.protobuf.ByteString getCertificateSignatureBytes(); 15 | 16 | /** string signature_correctness_proof = 2; */ 17 | String getSignatureCorrectnessProof(); 18 | /** string signature_correctness_proof = 2; */ 19 | com.google.protobuf.ByteString getSignatureCorrectnessProofBytes(); 20 | } 21 | -------------------------------------------------------------------------------- /sdk-scd/src/main/java/com/webank/wedpr/scd/proto/CertificateTemplateOrBuilder.java: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: scd.proto 3 | 4 | package com.webank.wedpr.scd.proto; 5 | 6 | public interface CertificateTemplateOrBuilder 7 | extends 8 | // @@protoc_insertion_point(interface_extends:com.webank.wedpr.scd.proto.CertificateTemplate) 9 | com.google.protobuf.MessageOrBuilder { 10 | 11 | /** .com.webank.wedpr.scd.proto.CertificateSchema certificate_schema = 1; */ 12 | boolean hasCertificateSchema(); 13 | /** .com.webank.wedpr.scd.proto.CertificateSchema certificate_schema = 1; */ 14 | com.webank.wedpr.scd.proto.CertificateSchema getCertificateSchema(); 15 | /** .com.webank.wedpr.scd.proto.CertificateSchema certificate_schema = 1; */ 16 | com.webank.wedpr.scd.proto.CertificateSchemaOrBuilder getCertificateSchemaOrBuilder(); 17 | 18 | /** string template_correctness_proof = 2; */ 19 | String getTemplateCorrectnessProof(); 20 | /** string template_correctness_proof = 2; */ 21 | com.google.protobuf.ByteString getTemplateCorrectnessProofBytes(); 22 | 23 | /** .com.webank.wedpr.scd.proto.TemplatePublicKey template_public_key = 3; */ 24 | boolean hasTemplatePublicKey(); 25 | /** .com.webank.wedpr.scd.proto.TemplatePublicKey template_public_key = 3; */ 26 | com.webank.wedpr.scd.proto.TemplatePublicKey getTemplatePublicKey(); 27 | /** .com.webank.wedpr.scd.proto.TemplatePublicKey template_public_key = 3; */ 28 | com.webank.wedpr.scd.proto.TemplatePublicKeyOrBuilder getTemplatePublicKeyOrBuilder(); 29 | } 30 | -------------------------------------------------------------------------------- /sdk-scd/src/main/java/com/webank/wedpr/scd/proto/PredicateOrBuilder.java: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: scd.proto 3 | 4 | package com.webank.wedpr.scd.proto; 5 | 6 | public interface PredicateOrBuilder 7 | extends 8 | // @@protoc_insertion_point(interface_extends:com.webank.wedpr.scd.proto.Predicate) 9 | com.google.protobuf.MessageOrBuilder { 10 | 11 | /** string attribute_name = 1; */ 12 | String getAttributeName(); 13 | /** string attribute_name = 1; */ 14 | com.google.protobuf.ByteString getAttributeNameBytes(); 15 | 16 | /** string predicate_type = 2; */ 17 | String getPredicateType(); 18 | /** string predicate_type = 2; */ 19 | com.google.protobuf.ByteString getPredicateTypeBytes(); 20 | 21 | /** uint64 predicate_value = 3; */ 22 | long getPredicateValue(); 23 | } 24 | -------------------------------------------------------------------------------- /sdk-scd/src/main/java/com/webank/wedpr/scd/proto/Scd.java: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: scd.proto 3 | 4 | package com.webank.wedpr.scd.proto; 5 | 6 | public final class Scd { 7 | private Scd() {} 8 | 9 | public static void registerAllExtensions(com.google.protobuf.ExtensionRegistryLite registry) {} 10 | 11 | public static void registerAllExtensions(com.google.protobuf.ExtensionRegistry registry) { 12 | registerAllExtensions((com.google.protobuf.ExtensionRegistryLite) registry); 13 | } 14 | 15 | static final com.google.protobuf.Descriptors.Descriptor 16 | internal_static_com_webank_wedpr_scd_proto_CertificateSchema_descriptor; 17 | static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable 18 | internal_static_com_webank_wedpr_scd_proto_CertificateSchema_fieldAccessorTable; 19 | static final com.google.protobuf.Descriptors.Descriptor 20 | internal_static_com_webank_wedpr_scd_proto_StringToStringPair_descriptor; 21 | static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable 22 | internal_static_com_webank_wedpr_scd_proto_StringToStringPair_fieldAccessorTable; 23 | static final com.google.protobuf.Descriptors.Descriptor 24 | internal_static_com_webank_wedpr_scd_proto_CertificateTemplate_descriptor; 25 | static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable 26 | internal_static_com_webank_wedpr_scd_proto_CertificateTemplate_fieldAccessorTable; 27 | static final com.google.protobuf.Descriptors.Descriptor 28 | internal_static_com_webank_wedpr_scd_proto_TemplatePublicKey_descriptor; 29 | static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable 30 | internal_static_com_webank_wedpr_scd_proto_TemplatePublicKey_fieldAccessorTable; 31 | static final com.google.protobuf.Descriptors.Descriptor 32 | internal_static_com_webank_wedpr_scd_proto_TemplatePrivateKey_descriptor; 33 | static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable 34 | internal_static_com_webank_wedpr_scd_proto_TemplatePrivateKey_fieldAccessorTable; 35 | static final com.google.protobuf.Descriptors.Descriptor 36 | internal_static_com_webank_wedpr_scd_proto_AttributeDict_descriptor; 37 | static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable 38 | internal_static_com_webank_wedpr_scd_proto_AttributeDict_fieldAccessorTable; 39 | static final com.google.protobuf.Descriptors.Descriptor 40 | internal_static_com_webank_wedpr_scd_proto_BlindedCertificateSecret_descriptor; 41 | static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable 42 | internal_static_com_webank_wedpr_scd_proto_BlindedCertificateSecret_fieldAccessorTable; 43 | static final com.google.protobuf.Descriptors.Descriptor 44 | internal_static_com_webank_wedpr_scd_proto_CertificateSignature_descriptor; 45 | static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable 46 | internal_static_com_webank_wedpr_scd_proto_CertificateSignature_fieldAccessorTable; 47 | static final com.google.protobuf.Descriptors.Descriptor 48 | internal_static_com_webank_wedpr_scd_proto_Predicate_descriptor; 49 | static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable 50 | internal_static_com_webank_wedpr_scd_proto_Predicate_fieldAccessorTable; 51 | static final com.google.protobuf.Descriptors.Descriptor 52 | internal_static_com_webank_wedpr_scd_proto_VerificationRuleSet_descriptor; 53 | static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable 54 | internal_static_com_webank_wedpr_scd_proto_VerificationRuleSet_fieldAccessorTable; 55 | static final com.google.protobuf.Descriptors.Descriptor 56 | internal_static_com_webank_wedpr_scd_proto_SignCertificateRequest_descriptor; 57 | static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable 58 | internal_static_com_webank_wedpr_scd_proto_SignCertificateRequest_fieldAccessorTable; 59 | static final com.google.protobuf.Descriptors.Descriptor 60 | internal_static_com_webank_wedpr_scd_proto_VerifyRequest_descriptor; 61 | static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable 62 | internal_static_com_webank_wedpr_scd_proto_VerifyRequest_fieldAccessorTable; 63 | static final com.google.protobuf.Descriptors.Descriptor 64 | internal_static_com_webank_wedpr_scd_proto_ScdResult_descriptor; 65 | static final com.google.protobuf.GeneratedMessageV3.FieldAccessorTable 66 | internal_static_com_webank_wedpr_scd_proto_ScdResult_fieldAccessorTable; 67 | 68 | public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { 69 | return descriptor; 70 | } 71 | 72 | private static com.google.protobuf.Descriptors.FileDescriptor descriptor; 73 | 74 | static { 75 | String[] descriptorData = { 76 | "\n\tscd.proto\022\032com.webank.wedpr.scd.proto\"" 77 | + "+\n\021CertificateSchema\022\026\n\016attribute_name\030\001" 78 | + " \003(\t\"0\n\022StringToStringPair\022\013\n\003key\030\001 \001(\t\022" 79 | + "\r\n\005value\030\002 \001(\t\"\320\001\n\023CertificateTemplate\022I" 80 | + "\n\022certificate_schema\030\001 \001(\0132-.com.webank." 81 | + "wedpr.scd.proto.CertificateSchema\022\"\n\032tem" 82 | + "plate_correctness_proof\030\002 \001(\t\022J\n\023templat" 83 | + "e_public_key\030\003 \001(\0132-.com.webank.wedpr.sc" 84 | + "d.proto.TemplatePublicKey\" \n\021TemplatePub" 85 | + "licKey\022\013\n\003key\030\001 \001(\t\"!\n\022TemplatePrivateKe" 86 | + "y\022\013\n\003key\030\001 \001(\t\"M\n\rAttributeDict\022<\n\004pair\030" 87 | + "\001 \003(\0132..com.webank.wedpr.scd.proto.Strin" 88 | + "gToStringPair\"v\n\030BlindedCertificateSecre" 89 | + "t\022#\n\033blinded_certificate_secrets\030\001 \001(\t\0225" 90 | + "\n-blinded_certificate_secrets_correctnes" 91 | + "s_proof\030\002 \001(\t\"Z\n\024CertificateSignature\022\035\n" 92 | + "\025certificate_signature\030\001 \001(\t\022#\n\033signatur" 93 | + "e_correctness_proof\030\002 \001(\t\"T\n\tPredicate\022\026" 94 | + "\n\016attribute_name\030\001 \001(\t\022\026\n\016predicate_type" 95 | + "\030\002 \001(\t\022\027\n\017predicate_value\030\003 \001(\004\"z\n\023Verif" 96 | + "icationRuleSet\022\037\n\027revealed_attribute_nam" 97 | + "e\030\001 \003(\t\022B\n\023attribute_predicate\030\002 \003(\0132%.c" 98 | + "om.webank.wedpr.scd.proto.Predicate\"\303\001\n\026" 99 | + "SignCertificateRequest\022M\n\032certificate_at" 100 | + "tribute_dict\030\001 \001(\0132).com.webank.wedpr.sc" 101 | + "d.proto.AttributeDict\022#\n\033blinded_certifi" 102 | + "cate_secrets\030\002 \001(\t\0225\n-blinded_certificat" 103 | + "e_secrets_correctness_proof\030\003 \001(\t\"\226\001\n\rVe" 104 | + "rifyRequest\022M\n\024certificate_template\030\001 \001(" 105 | + "\0132/.com.webank.wedpr.scd.proto.Certifica" 106 | + "teTemplate\022\032\n\022verification_proof\030\002 \001(\t\022\032" 107 | + "\n\022verification_nonce\030\003 \001(\t\"\201\005\n\tScdResult" 108 | + "\022M\n\024certificate_template\030\001 \001(\0132/.com.web" 109 | + "ank.wedpr.scd.proto.CertificateTemplate\022" 110 | + "L\n\024template_private_key\030\002 \001(\0132..com.weba" 111 | + "nk.wedpr.scd.proto.TemplatePrivateKey\022\024\n" 112 | + "\014issuer_nonce\030\003 \001(\t\022O\n\025certificate_signa" 113 | + "ture\030\004 \001(\01320.com.webank.wedpr.scd.proto." 114 | + "CertificateSignature\022\022\n\nuser_nonce\030\005 \001(\t" 115 | + "\022T\n\030sign_certificate_request\030\006 \001(\01322.com" 116 | + ".webank.wedpr.scd.proto.SignCertificateR" 117 | + "equest\022\030\n\020user_private_key\030\007 \001(\t\022,\n$cert" 118 | + "ificate_secrets_blinding_factors\030\010 \001(\t\022\032" 119 | + "\n\022verification_nonce\030\t \001(\t\022A\n\016verify_req" 120 | + "uest\030\n \001(\0132).com.webank.wedpr.scd.proto." 121 | + "VerifyRequest\022J\n\027revealed_attribute_dict" 122 | + "\030\013 \001(\0132).com.webank.wedpr.scd.proto.Attr" 123 | + "ibuteDict\022\023\n\013bool_result\030\014 \001(\010B\036\n\032com.we" 124 | + "bank.wedpr.scd.protoP\001b\006proto3" 125 | }; 126 | descriptor = 127 | com.google.protobuf.Descriptors.FileDescriptor.internalBuildGeneratedFileFrom( 128 | descriptorData, new com.google.protobuf.Descriptors.FileDescriptor[] {}); 129 | internal_static_com_webank_wedpr_scd_proto_CertificateSchema_descriptor = 130 | getDescriptor().getMessageTypes().get(0); 131 | internal_static_com_webank_wedpr_scd_proto_CertificateSchema_fieldAccessorTable = 132 | new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( 133 | internal_static_com_webank_wedpr_scd_proto_CertificateSchema_descriptor, 134 | new String[] { 135 | "AttributeName", 136 | }); 137 | internal_static_com_webank_wedpr_scd_proto_StringToStringPair_descriptor = 138 | getDescriptor().getMessageTypes().get(1); 139 | internal_static_com_webank_wedpr_scd_proto_StringToStringPair_fieldAccessorTable = 140 | new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( 141 | internal_static_com_webank_wedpr_scd_proto_StringToStringPair_descriptor, 142 | new String[] { 143 | "Key", "Value", 144 | }); 145 | internal_static_com_webank_wedpr_scd_proto_CertificateTemplate_descriptor = 146 | getDescriptor().getMessageTypes().get(2); 147 | internal_static_com_webank_wedpr_scd_proto_CertificateTemplate_fieldAccessorTable = 148 | new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( 149 | internal_static_com_webank_wedpr_scd_proto_CertificateTemplate_descriptor, 150 | new String[] { 151 | "CertificateSchema", "TemplateCorrectnessProof", "TemplatePublicKey", 152 | }); 153 | internal_static_com_webank_wedpr_scd_proto_TemplatePublicKey_descriptor = 154 | getDescriptor().getMessageTypes().get(3); 155 | internal_static_com_webank_wedpr_scd_proto_TemplatePublicKey_fieldAccessorTable = 156 | new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( 157 | internal_static_com_webank_wedpr_scd_proto_TemplatePublicKey_descriptor, 158 | new String[] { 159 | "Key", 160 | }); 161 | internal_static_com_webank_wedpr_scd_proto_TemplatePrivateKey_descriptor = 162 | getDescriptor().getMessageTypes().get(4); 163 | internal_static_com_webank_wedpr_scd_proto_TemplatePrivateKey_fieldAccessorTable = 164 | new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( 165 | internal_static_com_webank_wedpr_scd_proto_TemplatePrivateKey_descriptor, 166 | new String[] { 167 | "Key", 168 | }); 169 | internal_static_com_webank_wedpr_scd_proto_AttributeDict_descriptor = 170 | getDescriptor().getMessageTypes().get(5); 171 | internal_static_com_webank_wedpr_scd_proto_AttributeDict_fieldAccessorTable = 172 | new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( 173 | internal_static_com_webank_wedpr_scd_proto_AttributeDict_descriptor, 174 | new String[] { 175 | "Pair", 176 | }); 177 | internal_static_com_webank_wedpr_scd_proto_BlindedCertificateSecret_descriptor = 178 | getDescriptor().getMessageTypes().get(6); 179 | internal_static_com_webank_wedpr_scd_proto_BlindedCertificateSecret_fieldAccessorTable = 180 | new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( 181 | internal_static_com_webank_wedpr_scd_proto_BlindedCertificateSecret_descriptor, 182 | new String[] { 183 | "BlindedCertificateSecrets", 184 | "BlindedCertificateSecretsCorrectnessProof", 185 | }); 186 | internal_static_com_webank_wedpr_scd_proto_CertificateSignature_descriptor = 187 | getDescriptor().getMessageTypes().get(7); 188 | internal_static_com_webank_wedpr_scd_proto_CertificateSignature_fieldAccessorTable = 189 | new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( 190 | internal_static_com_webank_wedpr_scd_proto_CertificateSignature_descriptor, 191 | new String[] { 192 | "CertificateSignature", "SignatureCorrectnessProof", 193 | }); 194 | internal_static_com_webank_wedpr_scd_proto_Predicate_descriptor = 195 | getDescriptor().getMessageTypes().get(8); 196 | internal_static_com_webank_wedpr_scd_proto_Predicate_fieldAccessorTable = 197 | new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( 198 | internal_static_com_webank_wedpr_scd_proto_Predicate_descriptor, 199 | new String[] { 200 | "AttributeName", "PredicateType", "PredicateValue", 201 | }); 202 | internal_static_com_webank_wedpr_scd_proto_VerificationRuleSet_descriptor = 203 | getDescriptor().getMessageTypes().get(9); 204 | internal_static_com_webank_wedpr_scd_proto_VerificationRuleSet_fieldAccessorTable = 205 | new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( 206 | internal_static_com_webank_wedpr_scd_proto_VerificationRuleSet_descriptor, 207 | new String[] { 208 | "RevealedAttributeName", "AttributePredicate", 209 | }); 210 | internal_static_com_webank_wedpr_scd_proto_SignCertificateRequest_descriptor = 211 | getDescriptor().getMessageTypes().get(10); 212 | internal_static_com_webank_wedpr_scd_proto_SignCertificateRequest_fieldAccessorTable = 213 | new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( 214 | internal_static_com_webank_wedpr_scd_proto_SignCertificateRequest_descriptor, 215 | new String[] { 216 | "CertificateAttributeDict", 217 | "BlindedCertificateSecrets", 218 | "BlindedCertificateSecretsCorrectnessProof", 219 | }); 220 | internal_static_com_webank_wedpr_scd_proto_VerifyRequest_descriptor = 221 | getDescriptor().getMessageTypes().get(11); 222 | internal_static_com_webank_wedpr_scd_proto_VerifyRequest_fieldAccessorTable = 223 | new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( 224 | internal_static_com_webank_wedpr_scd_proto_VerifyRequest_descriptor, 225 | new String[] { 226 | "CertificateTemplate", "VerificationProof", "VerificationNonce", 227 | }); 228 | internal_static_com_webank_wedpr_scd_proto_ScdResult_descriptor = 229 | getDescriptor().getMessageTypes().get(12); 230 | internal_static_com_webank_wedpr_scd_proto_ScdResult_fieldAccessorTable = 231 | new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( 232 | internal_static_com_webank_wedpr_scd_proto_ScdResult_descriptor, 233 | new String[] { 234 | "CertificateTemplate", 235 | "TemplatePrivateKey", 236 | "IssuerNonce", 237 | "CertificateSignature", 238 | "UserNonce", 239 | "SignCertificateRequest", 240 | "UserPrivateKey", 241 | "CertificateSecretsBlindingFactors", 242 | "VerificationNonce", 243 | "VerifyRequest", 244 | "RevealedAttributeDict", 245 | "BoolResult", 246 | }); 247 | } 248 | 249 | // @@protoc_insertion_point(outer_class_scope) 250 | } 251 | -------------------------------------------------------------------------------- /sdk-scd/src/main/java/com/webank/wedpr/scd/proto/ScdResultOrBuilder.java: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: scd.proto 3 | 4 | package com.webank.wedpr.scd.proto; 5 | 6 | public interface ScdResultOrBuilder 7 | extends 8 | // @@protoc_insertion_point(interface_extends:com.webank.wedpr.scd.proto.ScdResult) 9 | com.google.protobuf.MessageOrBuilder { 10 | 11 | /** 12 | * 13 | * 14 | *

 15 |      * Used by the issuer.
 16 |      * 
17 | * 18 | * .com.webank.wedpr.scd.proto.CertificateTemplate certificate_template = 1; 19 | */ 20 | boolean hasCertificateTemplate(); 21 | /** 22 | * 23 | * 24 | *
 25 |      * Used by the issuer.
 26 |      * 
27 | * 28 | * .com.webank.wedpr.scd.proto.CertificateTemplate certificate_template = 1; 29 | */ 30 | com.webank.wedpr.scd.proto.CertificateTemplate getCertificateTemplate(); 31 | /** 32 | * 33 | * 34 | *
 35 |      * Used by the issuer.
 36 |      * 
37 | * 38 | * .com.webank.wedpr.scd.proto.CertificateTemplate certificate_template = 1; 39 | */ 40 | com.webank.wedpr.scd.proto.CertificateTemplateOrBuilder getCertificateTemplateOrBuilder(); 41 | 42 | /** .com.webank.wedpr.scd.proto.TemplatePrivateKey template_private_key = 2; */ 43 | boolean hasTemplatePrivateKey(); 44 | /** .com.webank.wedpr.scd.proto.TemplatePrivateKey template_private_key = 2; */ 45 | com.webank.wedpr.scd.proto.TemplatePrivateKey getTemplatePrivateKey(); 46 | /** .com.webank.wedpr.scd.proto.TemplatePrivateKey template_private_key = 2; */ 47 | com.webank.wedpr.scd.proto.TemplatePrivateKeyOrBuilder getTemplatePrivateKeyOrBuilder(); 48 | 49 | /** string issuer_nonce = 3; */ 50 | String getIssuerNonce(); 51 | /** string issuer_nonce = 3; */ 52 | com.google.protobuf.ByteString getIssuerNonceBytes(); 53 | 54 | /** 55 | * 56 | * 57 | *
 58 |      * Used by the user.
 59 |      * 
60 | * 61 | * .com.webank.wedpr.scd.proto.CertificateSignature certificate_signature = 4; 62 | */ 63 | boolean hasCertificateSignature(); 64 | /** 65 | * 66 | * 67 | *
 68 |      * Used by the user.
 69 |      * 
70 | * 71 | * .com.webank.wedpr.scd.proto.CertificateSignature certificate_signature = 4; 72 | */ 73 | com.webank.wedpr.scd.proto.CertificateSignature getCertificateSignature(); 74 | /** 75 | * 76 | * 77 | *
 78 |      * Used by the user.
 79 |      * 
80 | * 81 | * .com.webank.wedpr.scd.proto.CertificateSignature certificate_signature = 4; 82 | */ 83 | com.webank.wedpr.scd.proto.CertificateSignatureOrBuilder getCertificateSignatureOrBuilder(); 84 | 85 | /** string user_nonce = 5; */ 86 | String getUserNonce(); 87 | /** string user_nonce = 5; */ 88 | com.google.protobuf.ByteString getUserNonceBytes(); 89 | 90 | /** 91 | * .com.webank.wedpr.scd.proto.SignCertificateRequest sign_certificate_request = 6; 92 | */ 93 | boolean hasSignCertificateRequest(); 94 | /** 95 | * .com.webank.wedpr.scd.proto.SignCertificateRequest sign_certificate_request = 6; 96 | */ 97 | com.webank.wedpr.scd.proto.SignCertificateRequest getSignCertificateRequest(); 98 | /** 99 | * .com.webank.wedpr.scd.proto.SignCertificateRequest sign_certificate_request = 6; 100 | */ 101 | com.webank.wedpr.scd.proto.SignCertificateRequestOrBuilder getSignCertificateRequestOrBuilder(); 102 | 103 | /** string user_private_key = 7; */ 104 | String getUserPrivateKey(); 105 | /** string user_private_key = 7; */ 106 | com.google.protobuf.ByteString getUserPrivateKeyBytes(); 107 | 108 | /** string certificate_secrets_blinding_factors = 8; */ 109 | String getCertificateSecretsBlindingFactors(); 110 | /** string certificate_secrets_blinding_factors = 8; */ 111 | com.google.protobuf.ByteString getCertificateSecretsBlindingFactorsBytes(); 112 | 113 | /** 114 | * 115 | * 116 | *
117 |      * Used by the verifier.
118 |      * 
119 | * 120 | * string verification_nonce = 9; 121 | */ 122 | String getVerificationNonce(); 123 | /** 124 | * 125 | * 126 | *
127 |      * Used by the verifier.
128 |      * 
129 | * 130 | * string verification_nonce = 9; 131 | */ 132 | com.google.protobuf.ByteString getVerificationNonceBytes(); 133 | 134 | /** .com.webank.wedpr.scd.proto.VerifyRequest verify_request = 10; */ 135 | boolean hasVerifyRequest(); 136 | /** .com.webank.wedpr.scd.proto.VerifyRequest verify_request = 10; */ 137 | com.webank.wedpr.scd.proto.VerifyRequest getVerifyRequest(); 138 | /** .com.webank.wedpr.scd.proto.VerifyRequest verify_request = 10; */ 139 | com.webank.wedpr.scd.proto.VerifyRequestOrBuilder getVerifyRequestOrBuilder(); 140 | 141 | /** .com.webank.wedpr.scd.proto.AttributeDict revealed_attribute_dict = 11; */ 142 | boolean hasRevealedAttributeDict(); 143 | /** .com.webank.wedpr.scd.proto.AttributeDict revealed_attribute_dict = 11; */ 144 | com.webank.wedpr.scd.proto.AttributeDict getRevealedAttributeDict(); 145 | /** .com.webank.wedpr.scd.proto.AttributeDict revealed_attribute_dict = 11; */ 146 | com.webank.wedpr.scd.proto.AttributeDictOrBuilder getRevealedAttributeDictOrBuilder(); 147 | 148 | /** bool bool_result = 12; */ 149 | boolean getBoolResult(); 150 | } 151 | -------------------------------------------------------------------------------- /sdk-scd/src/main/java/com/webank/wedpr/scd/proto/SignCertificateRequestOrBuilder.java: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: scd.proto 3 | 4 | package com.webank.wedpr.scd.proto; 5 | 6 | public interface SignCertificateRequestOrBuilder 7 | extends 8 | // @@protoc_insertion_point(interface_extends:com.webank.wedpr.scd.proto.SignCertificateRequest) 9 | com.google.protobuf.MessageOrBuilder { 10 | 11 | /** .com.webank.wedpr.scd.proto.AttributeDict certificate_attribute_dict = 1; */ 12 | boolean hasCertificateAttributeDict(); 13 | /** .com.webank.wedpr.scd.proto.AttributeDict certificate_attribute_dict = 1; */ 14 | com.webank.wedpr.scd.proto.AttributeDict getCertificateAttributeDict(); 15 | /** .com.webank.wedpr.scd.proto.AttributeDict certificate_attribute_dict = 1; */ 16 | com.webank.wedpr.scd.proto.AttributeDictOrBuilder getCertificateAttributeDictOrBuilder(); 17 | 18 | /** string blinded_certificate_secrets = 2; */ 19 | String getBlindedCertificateSecrets(); 20 | /** string blinded_certificate_secrets = 2; */ 21 | com.google.protobuf.ByteString getBlindedCertificateSecretsBytes(); 22 | 23 | /** string blinded_certificate_secrets_correctness_proof = 3; */ 24 | String getBlindedCertificateSecretsCorrectnessProof(); 25 | /** string blinded_certificate_secrets_correctness_proof = 3; */ 26 | com.google.protobuf.ByteString getBlindedCertificateSecretsCorrectnessProofBytes(); 27 | } 28 | -------------------------------------------------------------------------------- /sdk-scd/src/main/java/com/webank/wedpr/scd/proto/StringToStringPairOrBuilder.java: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: scd.proto 3 | 4 | package com.webank.wedpr.scd.proto; 5 | 6 | public interface StringToStringPairOrBuilder 7 | extends 8 | // @@protoc_insertion_point(interface_extends:com.webank.wedpr.scd.proto.StringToStringPair) 9 | com.google.protobuf.MessageOrBuilder { 10 | 11 | /** string key = 1; */ 12 | String getKey(); 13 | /** string key = 1; */ 14 | com.google.protobuf.ByteString getKeyBytes(); 15 | 16 | /** string value = 2; */ 17 | String getValue(); 18 | /** string value = 2; */ 19 | com.google.protobuf.ByteString getValueBytes(); 20 | } 21 | -------------------------------------------------------------------------------- /sdk-scd/src/main/java/com/webank/wedpr/scd/proto/TemplatePrivateKey.java: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: scd.proto 3 | 4 | package com.webank.wedpr.scd.proto; 5 | 6 | /** 7 | * 8 | * 9 | *
 10 |  * Template private key.
 11 |  * 
12 | * 13 | * Protobuf type {@code com.webank.wedpr.scd.proto.TemplatePrivateKey} 14 | */ 15 | public final class TemplatePrivateKey extends com.google.protobuf.GeneratedMessageV3 16 | implements 17 | // @@protoc_insertion_point(message_implements:com.webank.wedpr.scd.proto.TemplatePrivateKey) 18 | TemplatePrivateKeyOrBuilder { 19 | private static final long serialVersionUID = 0L; 20 | // Use TemplatePrivateKey.newBuilder() to construct. 21 | private TemplatePrivateKey(com.google.protobuf.GeneratedMessageV3.Builder builder) { 22 | super(builder); 23 | } 24 | 25 | private TemplatePrivateKey() { 26 | key_ = ""; 27 | } 28 | 29 | @Override 30 | @SuppressWarnings({"unused"}) 31 | protected Object newInstance(UnusedPrivateParameter unused) { 32 | return new TemplatePrivateKey(); 33 | } 34 | 35 | @Override 36 | public final com.google.protobuf.UnknownFieldSet getUnknownFields() { 37 | return this.unknownFields; 38 | } 39 | 40 | private TemplatePrivateKey( 41 | com.google.protobuf.CodedInputStream input, 42 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 43 | throws com.google.protobuf.InvalidProtocolBufferException { 44 | this(); 45 | if (extensionRegistry == null) { 46 | throw new NullPointerException(); 47 | } 48 | com.google.protobuf.UnknownFieldSet.Builder unknownFields = 49 | com.google.protobuf.UnknownFieldSet.newBuilder(); 50 | try { 51 | boolean done = false; 52 | while (!done) { 53 | int tag = input.readTag(); 54 | switch (tag) { 55 | case 0: 56 | done = true; 57 | break; 58 | case 10: 59 | { 60 | String s = input.readStringRequireUtf8(); 61 | 62 | key_ = s; 63 | break; 64 | } 65 | default: 66 | { 67 | if (!parseUnknownField(input, unknownFields, extensionRegistry, tag)) { 68 | done = true; 69 | } 70 | break; 71 | } 72 | } 73 | } 74 | } catch (com.google.protobuf.InvalidProtocolBufferException e) { 75 | throw e.setUnfinishedMessage(this); 76 | } catch (java.io.IOException e) { 77 | throw new com.google.protobuf.InvalidProtocolBufferException(e) 78 | .setUnfinishedMessage(this); 79 | } finally { 80 | this.unknownFields = unknownFields.build(); 81 | makeExtensionsImmutable(); 82 | } 83 | } 84 | 85 | public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { 86 | return com.webank.wedpr.scd.proto.Scd 87 | .internal_static_com_webank_wedpr_scd_proto_TemplatePrivateKey_descriptor; 88 | } 89 | 90 | @Override 91 | protected FieldAccessorTable internalGetFieldAccessorTable() { 92 | return com.webank.wedpr.scd.proto.Scd 93 | .internal_static_com_webank_wedpr_scd_proto_TemplatePrivateKey_fieldAccessorTable 94 | .ensureFieldAccessorsInitialized( 95 | com.webank.wedpr.scd.proto.TemplatePrivateKey.class, 96 | com.webank.wedpr.scd.proto.TemplatePrivateKey.Builder.class); 97 | } 98 | 99 | public static final int KEY_FIELD_NUMBER = 1; 100 | private volatile Object key_; 101 | /** string key = 1; */ 102 | public String getKey() { 103 | Object ref = key_; 104 | if (ref instanceof String) { 105 | return (String) ref; 106 | } else { 107 | com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; 108 | String s = bs.toStringUtf8(); 109 | key_ = s; 110 | return s; 111 | } 112 | } 113 | /** string key = 1; */ 114 | public com.google.protobuf.ByteString getKeyBytes() { 115 | Object ref = key_; 116 | if (ref instanceof String) { 117 | com.google.protobuf.ByteString b = 118 | com.google.protobuf.ByteString.copyFromUtf8((String) ref); 119 | key_ = b; 120 | return b; 121 | } else { 122 | return (com.google.protobuf.ByteString) ref; 123 | } 124 | } 125 | 126 | private byte memoizedIsInitialized = -1; 127 | 128 | @Override 129 | public final boolean isInitialized() { 130 | byte isInitialized = memoizedIsInitialized; 131 | if (isInitialized == 1) return true; 132 | if (isInitialized == 0) return false; 133 | 134 | memoizedIsInitialized = 1; 135 | return true; 136 | } 137 | 138 | @Override 139 | public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { 140 | if (!getKeyBytes().isEmpty()) { 141 | com.google.protobuf.GeneratedMessageV3.writeString(output, 1, key_); 142 | } 143 | unknownFields.writeTo(output); 144 | } 145 | 146 | @Override 147 | public int getSerializedSize() { 148 | int size = memoizedSize; 149 | if (size != -1) return size; 150 | 151 | size = 0; 152 | if (!getKeyBytes().isEmpty()) { 153 | size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, key_); 154 | } 155 | size += unknownFields.getSerializedSize(); 156 | memoizedSize = size; 157 | return size; 158 | } 159 | 160 | @Override 161 | public boolean equals(final Object obj) { 162 | if (obj == this) { 163 | return true; 164 | } 165 | if (!(obj instanceof com.webank.wedpr.scd.proto.TemplatePrivateKey)) { 166 | return super.equals(obj); 167 | } 168 | com.webank.wedpr.scd.proto.TemplatePrivateKey other = 169 | (com.webank.wedpr.scd.proto.TemplatePrivateKey) obj; 170 | 171 | if (!getKey().equals(other.getKey())) return false; 172 | if (!unknownFields.equals(other.unknownFields)) return false; 173 | return true; 174 | } 175 | 176 | @Override 177 | public int hashCode() { 178 | if (memoizedHashCode != 0) { 179 | return memoizedHashCode; 180 | } 181 | int hash = 41; 182 | hash = (19 * hash) + getDescriptor().hashCode(); 183 | hash = (37 * hash) + KEY_FIELD_NUMBER; 184 | hash = (53 * hash) + getKey().hashCode(); 185 | hash = (29 * hash) + unknownFields.hashCode(); 186 | memoizedHashCode = hash; 187 | return hash; 188 | } 189 | 190 | public static com.webank.wedpr.scd.proto.TemplatePrivateKey parseFrom(java.nio.ByteBuffer data) 191 | throws com.google.protobuf.InvalidProtocolBufferException { 192 | return PARSER.parseFrom(data); 193 | } 194 | 195 | public static com.webank.wedpr.scd.proto.TemplatePrivateKey parseFrom( 196 | java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) 197 | throws com.google.protobuf.InvalidProtocolBufferException { 198 | return PARSER.parseFrom(data, extensionRegistry); 199 | } 200 | 201 | public static com.webank.wedpr.scd.proto.TemplatePrivateKey parseFrom( 202 | com.google.protobuf.ByteString data) 203 | throws com.google.protobuf.InvalidProtocolBufferException { 204 | return PARSER.parseFrom(data); 205 | } 206 | 207 | public static com.webank.wedpr.scd.proto.TemplatePrivateKey parseFrom( 208 | com.google.protobuf.ByteString data, 209 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 210 | throws com.google.protobuf.InvalidProtocolBufferException { 211 | return PARSER.parseFrom(data, extensionRegistry); 212 | } 213 | 214 | public static com.webank.wedpr.scd.proto.TemplatePrivateKey parseFrom(byte[] data) 215 | throws com.google.protobuf.InvalidProtocolBufferException { 216 | return PARSER.parseFrom(data); 217 | } 218 | 219 | public static com.webank.wedpr.scd.proto.TemplatePrivateKey parseFrom( 220 | byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) 221 | throws com.google.protobuf.InvalidProtocolBufferException { 222 | return PARSER.parseFrom(data, extensionRegistry); 223 | } 224 | 225 | public static com.webank.wedpr.scd.proto.TemplatePrivateKey parseFrom(java.io.InputStream input) 226 | throws java.io.IOException { 227 | return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); 228 | } 229 | 230 | public static com.webank.wedpr.scd.proto.TemplatePrivateKey parseFrom( 231 | java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) 232 | throws java.io.IOException { 233 | return com.google.protobuf.GeneratedMessageV3.parseWithIOException( 234 | PARSER, input, extensionRegistry); 235 | } 236 | 237 | public static com.webank.wedpr.scd.proto.TemplatePrivateKey parseDelimitedFrom( 238 | java.io.InputStream input) throws java.io.IOException { 239 | return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input); 240 | } 241 | 242 | public static com.webank.wedpr.scd.proto.TemplatePrivateKey parseDelimitedFrom( 243 | java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) 244 | throws java.io.IOException { 245 | return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException( 246 | PARSER, input, extensionRegistry); 247 | } 248 | 249 | public static com.webank.wedpr.scd.proto.TemplatePrivateKey parseFrom( 250 | com.google.protobuf.CodedInputStream input) throws java.io.IOException { 251 | return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); 252 | } 253 | 254 | public static com.webank.wedpr.scd.proto.TemplatePrivateKey parseFrom( 255 | com.google.protobuf.CodedInputStream input, 256 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 257 | throws java.io.IOException { 258 | return com.google.protobuf.GeneratedMessageV3.parseWithIOException( 259 | PARSER, input, extensionRegistry); 260 | } 261 | 262 | @Override 263 | public Builder newBuilderForType() { 264 | return newBuilder(); 265 | } 266 | 267 | public static Builder newBuilder() { 268 | return DEFAULT_INSTANCE.toBuilder(); 269 | } 270 | 271 | public static Builder newBuilder(com.webank.wedpr.scd.proto.TemplatePrivateKey prototype) { 272 | return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); 273 | } 274 | 275 | @Override 276 | public Builder toBuilder() { 277 | return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); 278 | } 279 | 280 | @Override 281 | protected Builder newBuilderForType(BuilderParent parent) { 282 | Builder builder = new Builder(parent); 283 | return builder; 284 | } 285 | /** 286 | * 287 | * 288 | *
289 |      * Template private key.
290 |      * 
291 | * 292 | * Protobuf type {@code com.webank.wedpr.scd.proto.TemplatePrivateKey} 293 | */ 294 | public static final class Builder 295 | extends com.google.protobuf.GeneratedMessageV3.Builder 296 | implements 297 | // @@protoc_insertion_point(builder_implements:com.webank.wedpr.scd.proto.TemplatePrivateKey) 298 | com.webank.wedpr.scd.proto.TemplatePrivateKeyOrBuilder { 299 | public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { 300 | return com.webank.wedpr.scd.proto.Scd 301 | .internal_static_com_webank_wedpr_scd_proto_TemplatePrivateKey_descriptor; 302 | } 303 | 304 | @Override 305 | protected FieldAccessorTable internalGetFieldAccessorTable() { 306 | return com.webank.wedpr.scd.proto.Scd 307 | .internal_static_com_webank_wedpr_scd_proto_TemplatePrivateKey_fieldAccessorTable 308 | .ensureFieldAccessorsInitialized( 309 | com.webank.wedpr.scd.proto.TemplatePrivateKey.class, 310 | com.webank.wedpr.scd.proto.TemplatePrivateKey.Builder.class); 311 | } 312 | 313 | // Construct using com.webank.wedpr.scd.proto.TemplatePrivateKey.newBuilder() 314 | private Builder() { 315 | maybeForceBuilderInitialization(); 316 | } 317 | 318 | private Builder(BuilderParent parent) { 319 | super(parent); 320 | maybeForceBuilderInitialization(); 321 | } 322 | 323 | private void maybeForceBuilderInitialization() { 324 | if (com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders) {} 325 | } 326 | 327 | @Override 328 | public Builder clear() { 329 | super.clear(); 330 | key_ = ""; 331 | 332 | return this; 333 | } 334 | 335 | @Override 336 | public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { 337 | return com.webank.wedpr.scd.proto.Scd 338 | .internal_static_com_webank_wedpr_scd_proto_TemplatePrivateKey_descriptor; 339 | } 340 | 341 | @Override 342 | public com.webank.wedpr.scd.proto.TemplatePrivateKey getDefaultInstanceForType() { 343 | return com.webank.wedpr.scd.proto.TemplatePrivateKey.getDefaultInstance(); 344 | } 345 | 346 | @Override 347 | public com.webank.wedpr.scd.proto.TemplatePrivateKey build() { 348 | com.webank.wedpr.scd.proto.TemplatePrivateKey result = buildPartial(); 349 | if (!result.isInitialized()) { 350 | throw newUninitializedMessageException(result); 351 | } 352 | return result; 353 | } 354 | 355 | @Override 356 | public com.webank.wedpr.scd.proto.TemplatePrivateKey buildPartial() { 357 | com.webank.wedpr.scd.proto.TemplatePrivateKey result = 358 | new com.webank.wedpr.scd.proto.TemplatePrivateKey(this); 359 | result.key_ = key_; 360 | onBuilt(); 361 | return result; 362 | } 363 | 364 | @Override 365 | public Builder clone() { 366 | return super.clone(); 367 | } 368 | 369 | @Override 370 | public Builder setField( 371 | com.google.protobuf.Descriptors.FieldDescriptor field, Object value) { 372 | return super.setField(field, value); 373 | } 374 | 375 | @Override 376 | public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) { 377 | return super.clearField(field); 378 | } 379 | 380 | @Override 381 | public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) { 382 | return super.clearOneof(oneof); 383 | } 384 | 385 | @Override 386 | public Builder setRepeatedField( 387 | com.google.protobuf.Descriptors.FieldDescriptor field, int index, Object value) { 388 | return super.setRepeatedField(field, index, value); 389 | } 390 | 391 | @Override 392 | public Builder addRepeatedField( 393 | com.google.protobuf.Descriptors.FieldDescriptor field, Object value) { 394 | return super.addRepeatedField(field, value); 395 | } 396 | 397 | @Override 398 | public Builder mergeFrom(com.google.protobuf.Message other) { 399 | if (other instanceof com.webank.wedpr.scd.proto.TemplatePrivateKey) { 400 | return mergeFrom((com.webank.wedpr.scd.proto.TemplatePrivateKey) other); 401 | } else { 402 | super.mergeFrom(other); 403 | return this; 404 | } 405 | } 406 | 407 | public Builder mergeFrom(com.webank.wedpr.scd.proto.TemplatePrivateKey other) { 408 | if (other == com.webank.wedpr.scd.proto.TemplatePrivateKey.getDefaultInstance()) 409 | return this; 410 | if (!other.getKey().isEmpty()) { 411 | key_ = other.key_; 412 | onChanged(); 413 | } 414 | this.mergeUnknownFields(other.unknownFields); 415 | onChanged(); 416 | return this; 417 | } 418 | 419 | @Override 420 | public final boolean isInitialized() { 421 | return true; 422 | } 423 | 424 | @Override 425 | public Builder mergeFrom( 426 | com.google.protobuf.CodedInputStream input, 427 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 428 | throws java.io.IOException { 429 | com.webank.wedpr.scd.proto.TemplatePrivateKey parsedMessage = null; 430 | try { 431 | parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); 432 | } catch (com.google.protobuf.InvalidProtocolBufferException e) { 433 | parsedMessage = 434 | (com.webank.wedpr.scd.proto.TemplatePrivateKey) e.getUnfinishedMessage(); 435 | throw e.unwrapIOException(); 436 | } finally { 437 | if (parsedMessage != null) { 438 | mergeFrom(parsedMessage); 439 | } 440 | } 441 | return this; 442 | } 443 | 444 | private Object key_ = ""; 445 | /** string key = 1; */ 446 | public String getKey() { 447 | Object ref = key_; 448 | if (!(ref instanceof String)) { 449 | com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; 450 | String s = bs.toStringUtf8(); 451 | key_ = s; 452 | return s; 453 | } else { 454 | return (String) ref; 455 | } 456 | } 457 | /** string key = 1; */ 458 | public com.google.protobuf.ByteString getKeyBytes() { 459 | Object ref = key_; 460 | if (ref instanceof String) { 461 | com.google.protobuf.ByteString b = 462 | com.google.protobuf.ByteString.copyFromUtf8((String) ref); 463 | key_ = b; 464 | return b; 465 | } else { 466 | return (com.google.protobuf.ByteString) ref; 467 | } 468 | } 469 | /** string key = 1; */ 470 | public Builder setKey(String value) { 471 | if (value == null) { 472 | throw new NullPointerException(); 473 | } 474 | 475 | key_ = value; 476 | onChanged(); 477 | return this; 478 | } 479 | /** string key = 1; */ 480 | public Builder clearKey() { 481 | 482 | key_ = getDefaultInstance().getKey(); 483 | onChanged(); 484 | return this; 485 | } 486 | /** string key = 1; */ 487 | public Builder setKeyBytes(com.google.protobuf.ByteString value) { 488 | if (value == null) { 489 | throw new NullPointerException(); 490 | } 491 | checkByteStringIsUtf8(value); 492 | 493 | key_ = value; 494 | onChanged(); 495 | return this; 496 | } 497 | 498 | @Override 499 | public final Builder setUnknownFields( 500 | final com.google.protobuf.UnknownFieldSet unknownFields) { 501 | return super.setUnknownFields(unknownFields); 502 | } 503 | 504 | @Override 505 | public final Builder mergeUnknownFields( 506 | final com.google.protobuf.UnknownFieldSet unknownFields) { 507 | return super.mergeUnknownFields(unknownFields); 508 | } 509 | 510 | // @@protoc_insertion_point(builder_scope:com.webank.wedpr.scd.proto.TemplatePrivateKey) 511 | } 512 | 513 | // @@protoc_insertion_point(class_scope:com.webank.wedpr.scd.proto.TemplatePrivateKey) 514 | private static final com.webank.wedpr.scd.proto.TemplatePrivateKey DEFAULT_INSTANCE; 515 | 516 | static { 517 | DEFAULT_INSTANCE = new com.webank.wedpr.scd.proto.TemplatePrivateKey(); 518 | } 519 | 520 | public static com.webank.wedpr.scd.proto.TemplatePrivateKey getDefaultInstance() { 521 | return DEFAULT_INSTANCE; 522 | } 523 | 524 | private static final com.google.protobuf.Parser PARSER = 525 | new com.google.protobuf.AbstractParser() { 526 | @Override 527 | public TemplatePrivateKey parsePartialFrom( 528 | com.google.protobuf.CodedInputStream input, 529 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 530 | throws com.google.protobuf.InvalidProtocolBufferException { 531 | return new TemplatePrivateKey(input, extensionRegistry); 532 | } 533 | }; 534 | 535 | public static com.google.protobuf.Parser parser() { 536 | return PARSER; 537 | } 538 | 539 | @Override 540 | public com.google.protobuf.Parser getParserForType() { 541 | return PARSER; 542 | } 543 | 544 | @Override 545 | public com.webank.wedpr.scd.proto.TemplatePrivateKey getDefaultInstanceForType() { 546 | return DEFAULT_INSTANCE; 547 | } 548 | } 549 | -------------------------------------------------------------------------------- /sdk-scd/src/main/java/com/webank/wedpr/scd/proto/TemplatePrivateKeyOrBuilder.java: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: scd.proto 3 | 4 | package com.webank.wedpr.scd.proto; 5 | 6 | public interface TemplatePrivateKeyOrBuilder 7 | extends 8 | // @@protoc_insertion_point(interface_extends:com.webank.wedpr.scd.proto.TemplatePrivateKey) 9 | com.google.protobuf.MessageOrBuilder { 10 | 11 | /** string key = 1; */ 12 | String getKey(); 13 | /** string key = 1; */ 14 | com.google.protobuf.ByteString getKeyBytes(); 15 | } 16 | -------------------------------------------------------------------------------- /sdk-scd/src/main/java/com/webank/wedpr/scd/proto/TemplatePublicKey.java: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: scd.proto 3 | 4 | package com.webank.wedpr.scd.proto; 5 | 6 | /** 7 | * 8 | * 9 | *
 10 |  * Template public key.
 11 |  * 
12 | * 13 | * Protobuf type {@code com.webank.wedpr.scd.proto.TemplatePublicKey} 14 | */ 15 | public final class TemplatePublicKey extends com.google.protobuf.GeneratedMessageV3 16 | implements 17 | // @@protoc_insertion_point(message_implements:com.webank.wedpr.scd.proto.TemplatePublicKey) 18 | TemplatePublicKeyOrBuilder { 19 | private static final long serialVersionUID = 0L; 20 | // Use TemplatePublicKey.newBuilder() to construct. 21 | private TemplatePublicKey(com.google.protobuf.GeneratedMessageV3.Builder builder) { 22 | super(builder); 23 | } 24 | 25 | private TemplatePublicKey() { 26 | key_ = ""; 27 | } 28 | 29 | @Override 30 | @SuppressWarnings({"unused"}) 31 | protected Object newInstance(UnusedPrivateParameter unused) { 32 | return new TemplatePublicKey(); 33 | } 34 | 35 | @Override 36 | public final com.google.protobuf.UnknownFieldSet getUnknownFields() { 37 | return this.unknownFields; 38 | } 39 | 40 | private TemplatePublicKey( 41 | com.google.protobuf.CodedInputStream input, 42 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 43 | throws com.google.protobuf.InvalidProtocolBufferException { 44 | this(); 45 | if (extensionRegistry == null) { 46 | throw new NullPointerException(); 47 | } 48 | com.google.protobuf.UnknownFieldSet.Builder unknownFields = 49 | com.google.protobuf.UnknownFieldSet.newBuilder(); 50 | try { 51 | boolean done = false; 52 | while (!done) { 53 | int tag = input.readTag(); 54 | switch (tag) { 55 | case 0: 56 | done = true; 57 | break; 58 | case 10: 59 | { 60 | String s = input.readStringRequireUtf8(); 61 | 62 | key_ = s; 63 | break; 64 | } 65 | default: 66 | { 67 | if (!parseUnknownField(input, unknownFields, extensionRegistry, tag)) { 68 | done = true; 69 | } 70 | break; 71 | } 72 | } 73 | } 74 | } catch (com.google.protobuf.InvalidProtocolBufferException e) { 75 | throw e.setUnfinishedMessage(this); 76 | } catch (java.io.IOException e) { 77 | throw new com.google.protobuf.InvalidProtocolBufferException(e) 78 | .setUnfinishedMessage(this); 79 | } finally { 80 | this.unknownFields = unknownFields.build(); 81 | makeExtensionsImmutable(); 82 | } 83 | } 84 | 85 | public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { 86 | return com.webank.wedpr.scd.proto.Scd 87 | .internal_static_com_webank_wedpr_scd_proto_TemplatePublicKey_descriptor; 88 | } 89 | 90 | @Override 91 | protected FieldAccessorTable internalGetFieldAccessorTable() { 92 | return com.webank.wedpr.scd.proto.Scd 93 | .internal_static_com_webank_wedpr_scd_proto_TemplatePublicKey_fieldAccessorTable 94 | .ensureFieldAccessorsInitialized( 95 | com.webank.wedpr.scd.proto.TemplatePublicKey.class, 96 | com.webank.wedpr.scd.proto.TemplatePublicKey.Builder.class); 97 | } 98 | 99 | public static final int KEY_FIELD_NUMBER = 1; 100 | private volatile Object key_; 101 | /** string key = 1; */ 102 | public String getKey() { 103 | Object ref = key_; 104 | if (ref instanceof String) { 105 | return (String) ref; 106 | } else { 107 | com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; 108 | String s = bs.toStringUtf8(); 109 | key_ = s; 110 | return s; 111 | } 112 | } 113 | /** string key = 1; */ 114 | public com.google.protobuf.ByteString getKeyBytes() { 115 | Object ref = key_; 116 | if (ref instanceof String) { 117 | com.google.protobuf.ByteString b = 118 | com.google.protobuf.ByteString.copyFromUtf8((String) ref); 119 | key_ = b; 120 | return b; 121 | } else { 122 | return (com.google.protobuf.ByteString) ref; 123 | } 124 | } 125 | 126 | private byte memoizedIsInitialized = -1; 127 | 128 | @Override 129 | public final boolean isInitialized() { 130 | byte isInitialized = memoizedIsInitialized; 131 | if (isInitialized == 1) return true; 132 | if (isInitialized == 0) return false; 133 | 134 | memoizedIsInitialized = 1; 135 | return true; 136 | } 137 | 138 | @Override 139 | public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { 140 | if (!getKeyBytes().isEmpty()) { 141 | com.google.protobuf.GeneratedMessageV3.writeString(output, 1, key_); 142 | } 143 | unknownFields.writeTo(output); 144 | } 145 | 146 | @Override 147 | public int getSerializedSize() { 148 | int size = memoizedSize; 149 | if (size != -1) return size; 150 | 151 | size = 0; 152 | if (!getKeyBytes().isEmpty()) { 153 | size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, key_); 154 | } 155 | size += unknownFields.getSerializedSize(); 156 | memoizedSize = size; 157 | return size; 158 | } 159 | 160 | @Override 161 | public boolean equals(final Object obj) { 162 | if (obj == this) { 163 | return true; 164 | } 165 | if (!(obj instanceof com.webank.wedpr.scd.proto.TemplatePublicKey)) { 166 | return super.equals(obj); 167 | } 168 | com.webank.wedpr.scd.proto.TemplatePublicKey other = 169 | (com.webank.wedpr.scd.proto.TemplatePublicKey) obj; 170 | 171 | if (!getKey().equals(other.getKey())) return false; 172 | if (!unknownFields.equals(other.unknownFields)) return false; 173 | return true; 174 | } 175 | 176 | @Override 177 | public int hashCode() { 178 | if (memoizedHashCode != 0) { 179 | return memoizedHashCode; 180 | } 181 | int hash = 41; 182 | hash = (19 * hash) + getDescriptor().hashCode(); 183 | hash = (37 * hash) + KEY_FIELD_NUMBER; 184 | hash = (53 * hash) + getKey().hashCode(); 185 | hash = (29 * hash) + unknownFields.hashCode(); 186 | memoizedHashCode = hash; 187 | return hash; 188 | } 189 | 190 | public static com.webank.wedpr.scd.proto.TemplatePublicKey parseFrom(java.nio.ByteBuffer data) 191 | throws com.google.protobuf.InvalidProtocolBufferException { 192 | return PARSER.parseFrom(data); 193 | } 194 | 195 | public static com.webank.wedpr.scd.proto.TemplatePublicKey parseFrom( 196 | java.nio.ByteBuffer data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) 197 | throws com.google.protobuf.InvalidProtocolBufferException { 198 | return PARSER.parseFrom(data, extensionRegistry); 199 | } 200 | 201 | public static com.webank.wedpr.scd.proto.TemplatePublicKey parseFrom( 202 | com.google.protobuf.ByteString data) 203 | throws com.google.protobuf.InvalidProtocolBufferException { 204 | return PARSER.parseFrom(data); 205 | } 206 | 207 | public static com.webank.wedpr.scd.proto.TemplatePublicKey parseFrom( 208 | com.google.protobuf.ByteString data, 209 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 210 | throws com.google.protobuf.InvalidProtocolBufferException { 211 | return PARSER.parseFrom(data, extensionRegistry); 212 | } 213 | 214 | public static com.webank.wedpr.scd.proto.TemplatePublicKey parseFrom(byte[] data) 215 | throws com.google.protobuf.InvalidProtocolBufferException { 216 | return PARSER.parseFrom(data); 217 | } 218 | 219 | public static com.webank.wedpr.scd.proto.TemplatePublicKey parseFrom( 220 | byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) 221 | throws com.google.protobuf.InvalidProtocolBufferException { 222 | return PARSER.parseFrom(data, extensionRegistry); 223 | } 224 | 225 | public static com.webank.wedpr.scd.proto.TemplatePublicKey parseFrom(java.io.InputStream input) 226 | throws java.io.IOException { 227 | return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); 228 | } 229 | 230 | public static com.webank.wedpr.scd.proto.TemplatePublicKey parseFrom( 231 | java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) 232 | throws java.io.IOException { 233 | return com.google.protobuf.GeneratedMessageV3.parseWithIOException( 234 | PARSER, input, extensionRegistry); 235 | } 236 | 237 | public static com.webank.wedpr.scd.proto.TemplatePublicKey parseDelimitedFrom( 238 | java.io.InputStream input) throws java.io.IOException { 239 | return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException(PARSER, input); 240 | } 241 | 242 | public static com.webank.wedpr.scd.proto.TemplatePublicKey parseDelimitedFrom( 243 | java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) 244 | throws java.io.IOException { 245 | return com.google.protobuf.GeneratedMessageV3.parseDelimitedWithIOException( 246 | PARSER, input, extensionRegistry); 247 | } 248 | 249 | public static com.webank.wedpr.scd.proto.TemplatePublicKey parseFrom( 250 | com.google.protobuf.CodedInputStream input) throws java.io.IOException { 251 | return com.google.protobuf.GeneratedMessageV3.parseWithIOException(PARSER, input); 252 | } 253 | 254 | public static com.webank.wedpr.scd.proto.TemplatePublicKey parseFrom( 255 | com.google.protobuf.CodedInputStream input, 256 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 257 | throws java.io.IOException { 258 | return com.google.protobuf.GeneratedMessageV3.parseWithIOException( 259 | PARSER, input, extensionRegistry); 260 | } 261 | 262 | @Override 263 | public Builder newBuilderForType() { 264 | return newBuilder(); 265 | } 266 | 267 | public static Builder newBuilder() { 268 | return DEFAULT_INSTANCE.toBuilder(); 269 | } 270 | 271 | public static Builder newBuilder(com.webank.wedpr.scd.proto.TemplatePublicKey prototype) { 272 | return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); 273 | } 274 | 275 | @Override 276 | public Builder toBuilder() { 277 | return this == DEFAULT_INSTANCE ? new Builder() : new Builder().mergeFrom(this); 278 | } 279 | 280 | @Override 281 | protected Builder newBuilderForType(BuilderParent parent) { 282 | Builder builder = new Builder(parent); 283 | return builder; 284 | } 285 | /** 286 | * 287 | * 288 | *
289 |      * Template public key.
290 |      * 
291 | * 292 | * Protobuf type {@code com.webank.wedpr.scd.proto.TemplatePublicKey} 293 | */ 294 | public static final class Builder 295 | extends com.google.protobuf.GeneratedMessageV3.Builder 296 | implements 297 | // @@protoc_insertion_point(builder_implements:com.webank.wedpr.scd.proto.TemplatePublicKey) 298 | com.webank.wedpr.scd.proto.TemplatePublicKeyOrBuilder { 299 | public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { 300 | return com.webank.wedpr.scd.proto.Scd 301 | .internal_static_com_webank_wedpr_scd_proto_TemplatePublicKey_descriptor; 302 | } 303 | 304 | @Override 305 | protected FieldAccessorTable internalGetFieldAccessorTable() { 306 | return com.webank.wedpr.scd.proto.Scd 307 | .internal_static_com_webank_wedpr_scd_proto_TemplatePublicKey_fieldAccessorTable 308 | .ensureFieldAccessorsInitialized( 309 | com.webank.wedpr.scd.proto.TemplatePublicKey.class, 310 | com.webank.wedpr.scd.proto.TemplatePublicKey.Builder.class); 311 | } 312 | 313 | // Construct using com.webank.wedpr.scd.proto.TemplatePublicKey.newBuilder() 314 | private Builder() { 315 | maybeForceBuilderInitialization(); 316 | } 317 | 318 | private Builder(BuilderParent parent) { 319 | super(parent); 320 | maybeForceBuilderInitialization(); 321 | } 322 | 323 | private void maybeForceBuilderInitialization() { 324 | if (com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders) {} 325 | } 326 | 327 | @Override 328 | public Builder clear() { 329 | super.clear(); 330 | key_ = ""; 331 | 332 | return this; 333 | } 334 | 335 | @Override 336 | public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() { 337 | return com.webank.wedpr.scd.proto.Scd 338 | .internal_static_com_webank_wedpr_scd_proto_TemplatePublicKey_descriptor; 339 | } 340 | 341 | @Override 342 | public com.webank.wedpr.scd.proto.TemplatePublicKey getDefaultInstanceForType() { 343 | return com.webank.wedpr.scd.proto.TemplatePublicKey.getDefaultInstance(); 344 | } 345 | 346 | @Override 347 | public com.webank.wedpr.scd.proto.TemplatePublicKey build() { 348 | com.webank.wedpr.scd.proto.TemplatePublicKey result = buildPartial(); 349 | if (!result.isInitialized()) { 350 | throw newUninitializedMessageException(result); 351 | } 352 | return result; 353 | } 354 | 355 | @Override 356 | public com.webank.wedpr.scd.proto.TemplatePublicKey buildPartial() { 357 | com.webank.wedpr.scd.proto.TemplatePublicKey result = 358 | new com.webank.wedpr.scd.proto.TemplatePublicKey(this); 359 | result.key_ = key_; 360 | onBuilt(); 361 | return result; 362 | } 363 | 364 | @Override 365 | public Builder clone() { 366 | return super.clone(); 367 | } 368 | 369 | @Override 370 | public Builder setField( 371 | com.google.protobuf.Descriptors.FieldDescriptor field, Object value) { 372 | return super.setField(field, value); 373 | } 374 | 375 | @Override 376 | public Builder clearField(com.google.protobuf.Descriptors.FieldDescriptor field) { 377 | return super.clearField(field); 378 | } 379 | 380 | @Override 381 | public Builder clearOneof(com.google.protobuf.Descriptors.OneofDescriptor oneof) { 382 | return super.clearOneof(oneof); 383 | } 384 | 385 | @Override 386 | public Builder setRepeatedField( 387 | com.google.protobuf.Descriptors.FieldDescriptor field, int index, Object value) { 388 | return super.setRepeatedField(field, index, value); 389 | } 390 | 391 | @Override 392 | public Builder addRepeatedField( 393 | com.google.protobuf.Descriptors.FieldDescriptor field, Object value) { 394 | return super.addRepeatedField(field, value); 395 | } 396 | 397 | @Override 398 | public Builder mergeFrom(com.google.protobuf.Message other) { 399 | if (other instanceof com.webank.wedpr.scd.proto.TemplatePublicKey) { 400 | return mergeFrom((com.webank.wedpr.scd.proto.TemplatePublicKey) other); 401 | } else { 402 | super.mergeFrom(other); 403 | return this; 404 | } 405 | } 406 | 407 | public Builder mergeFrom(com.webank.wedpr.scd.proto.TemplatePublicKey other) { 408 | if (other == com.webank.wedpr.scd.proto.TemplatePublicKey.getDefaultInstance()) 409 | return this; 410 | if (!other.getKey().isEmpty()) { 411 | key_ = other.key_; 412 | onChanged(); 413 | } 414 | this.mergeUnknownFields(other.unknownFields); 415 | onChanged(); 416 | return this; 417 | } 418 | 419 | @Override 420 | public final boolean isInitialized() { 421 | return true; 422 | } 423 | 424 | @Override 425 | public Builder mergeFrom( 426 | com.google.protobuf.CodedInputStream input, 427 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 428 | throws java.io.IOException { 429 | com.webank.wedpr.scd.proto.TemplatePublicKey parsedMessage = null; 430 | try { 431 | parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); 432 | } catch (com.google.protobuf.InvalidProtocolBufferException e) { 433 | parsedMessage = 434 | (com.webank.wedpr.scd.proto.TemplatePublicKey) e.getUnfinishedMessage(); 435 | throw e.unwrapIOException(); 436 | } finally { 437 | if (parsedMessage != null) { 438 | mergeFrom(parsedMessage); 439 | } 440 | } 441 | return this; 442 | } 443 | 444 | private Object key_ = ""; 445 | /** string key = 1; */ 446 | public String getKey() { 447 | Object ref = key_; 448 | if (!(ref instanceof String)) { 449 | com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref; 450 | String s = bs.toStringUtf8(); 451 | key_ = s; 452 | return s; 453 | } else { 454 | return (String) ref; 455 | } 456 | } 457 | /** string key = 1; */ 458 | public com.google.protobuf.ByteString getKeyBytes() { 459 | Object ref = key_; 460 | if (ref instanceof String) { 461 | com.google.protobuf.ByteString b = 462 | com.google.protobuf.ByteString.copyFromUtf8((String) ref); 463 | key_ = b; 464 | return b; 465 | } else { 466 | return (com.google.protobuf.ByteString) ref; 467 | } 468 | } 469 | /** string key = 1; */ 470 | public Builder setKey(String value) { 471 | if (value == null) { 472 | throw new NullPointerException(); 473 | } 474 | 475 | key_ = value; 476 | onChanged(); 477 | return this; 478 | } 479 | /** string key = 1; */ 480 | public Builder clearKey() { 481 | 482 | key_ = getDefaultInstance().getKey(); 483 | onChanged(); 484 | return this; 485 | } 486 | /** string key = 1; */ 487 | public Builder setKeyBytes(com.google.protobuf.ByteString value) { 488 | if (value == null) { 489 | throw new NullPointerException(); 490 | } 491 | checkByteStringIsUtf8(value); 492 | 493 | key_ = value; 494 | onChanged(); 495 | return this; 496 | } 497 | 498 | @Override 499 | public final Builder setUnknownFields( 500 | final com.google.protobuf.UnknownFieldSet unknownFields) { 501 | return super.setUnknownFields(unknownFields); 502 | } 503 | 504 | @Override 505 | public final Builder mergeUnknownFields( 506 | final com.google.protobuf.UnknownFieldSet unknownFields) { 507 | return super.mergeUnknownFields(unknownFields); 508 | } 509 | 510 | // @@protoc_insertion_point(builder_scope:com.webank.wedpr.scd.proto.TemplatePublicKey) 511 | } 512 | 513 | // @@protoc_insertion_point(class_scope:com.webank.wedpr.scd.proto.TemplatePublicKey) 514 | private static final com.webank.wedpr.scd.proto.TemplatePublicKey DEFAULT_INSTANCE; 515 | 516 | static { 517 | DEFAULT_INSTANCE = new com.webank.wedpr.scd.proto.TemplatePublicKey(); 518 | } 519 | 520 | public static com.webank.wedpr.scd.proto.TemplatePublicKey getDefaultInstance() { 521 | return DEFAULT_INSTANCE; 522 | } 523 | 524 | private static final com.google.protobuf.Parser PARSER = 525 | new com.google.protobuf.AbstractParser() { 526 | @Override 527 | public TemplatePublicKey parsePartialFrom( 528 | com.google.protobuf.CodedInputStream input, 529 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 530 | throws com.google.protobuf.InvalidProtocolBufferException { 531 | return new TemplatePublicKey(input, extensionRegistry); 532 | } 533 | }; 534 | 535 | public static com.google.protobuf.Parser parser() { 536 | return PARSER; 537 | } 538 | 539 | @Override 540 | public com.google.protobuf.Parser getParserForType() { 541 | return PARSER; 542 | } 543 | 544 | @Override 545 | public com.webank.wedpr.scd.proto.TemplatePublicKey getDefaultInstanceForType() { 546 | return DEFAULT_INSTANCE; 547 | } 548 | } 549 | -------------------------------------------------------------------------------- /sdk-scd/src/main/java/com/webank/wedpr/scd/proto/TemplatePublicKeyOrBuilder.java: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: scd.proto 3 | 4 | package com.webank.wedpr.scd.proto; 5 | 6 | public interface TemplatePublicKeyOrBuilder 7 | extends 8 | // @@protoc_insertion_point(interface_extends:com.webank.wedpr.scd.proto.TemplatePublicKey) 9 | com.google.protobuf.MessageOrBuilder { 10 | 11 | /** string key = 1; */ 12 | String getKey(); 13 | /** string key = 1; */ 14 | com.google.protobuf.ByteString getKeyBytes(); 15 | } 16 | -------------------------------------------------------------------------------- /sdk-scd/src/main/java/com/webank/wedpr/scd/proto/VerificationRuleSetOrBuilder.java: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: scd.proto 3 | 4 | package com.webank.wedpr.scd.proto; 5 | 6 | public interface VerificationRuleSetOrBuilder 7 | extends 8 | // @@protoc_insertion_point(interface_extends:com.webank.wedpr.scd.proto.VerificationRuleSet) 9 | com.google.protobuf.MessageOrBuilder { 10 | 11 | /** repeated string revealed_attribute_name = 1; */ 12 | java.util.List getRevealedAttributeNameList(); 13 | /** repeated string revealed_attribute_name = 1; */ 14 | int getRevealedAttributeNameCount(); 15 | /** repeated string revealed_attribute_name = 1; */ 16 | String getRevealedAttributeName(int index); 17 | /** repeated string revealed_attribute_name = 1; */ 18 | com.google.protobuf.ByteString getRevealedAttributeNameBytes(int index); 19 | 20 | /** repeated .com.webank.wedpr.scd.proto.Predicate attribute_predicate = 2; */ 21 | java.util.List getAttributePredicateList(); 22 | /** repeated .com.webank.wedpr.scd.proto.Predicate attribute_predicate = 2; */ 23 | com.webank.wedpr.scd.proto.Predicate getAttributePredicate(int index); 24 | /** repeated .com.webank.wedpr.scd.proto.Predicate attribute_predicate = 2; */ 25 | int getAttributePredicateCount(); 26 | /** repeated .com.webank.wedpr.scd.proto.Predicate attribute_predicate = 2; */ 27 | java.util.List 28 | getAttributePredicateOrBuilderList(); 29 | /** repeated .com.webank.wedpr.scd.proto.Predicate attribute_predicate = 2; */ 30 | com.webank.wedpr.scd.proto.PredicateOrBuilder getAttributePredicateOrBuilder(int index); 31 | } 32 | -------------------------------------------------------------------------------- /sdk-scd/src/main/java/com/webank/wedpr/scd/proto/VerifyRequestOrBuilder.java: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: scd.proto 3 | 4 | package com.webank.wedpr.scd.proto; 5 | 6 | public interface VerifyRequestOrBuilder 7 | extends 8 | // @@protoc_insertion_point(interface_extends:com.webank.wedpr.scd.proto.VerifyRequest) 9 | com.google.protobuf.MessageOrBuilder { 10 | 11 | /** .com.webank.wedpr.scd.proto.CertificateTemplate certificate_template = 1; */ 12 | boolean hasCertificateTemplate(); 13 | /** .com.webank.wedpr.scd.proto.CertificateTemplate certificate_template = 1; */ 14 | com.webank.wedpr.scd.proto.CertificateTemplate getCertificateTemplate(); 15 | /** .com.webank.wedpr.scd.proto.CertificateTemplate certificate_template = 1; */ 16 | com.webank.wedpr.scd.proto.CertificateTemplateOrBuilder getCertificateTemplateOrBuilder(); 17 | 18 | /** string verification_proof = 2; */ 19 | String getVerificationProof(); 20 | /** string verification_proof = 2; */ 21 | com.google.protobuf.ByteString getVerificationProofBytes(); 22 | 23 | /** string verification_nonce = 3; */ 24 | String getVerificationNonce(); 25 | /** string verification_nonce = 3; */ 26 | com.google.protobuf.ByteString getVerificationNonceBytes(); 27 | } 28 | -------------------------------------------------------------------------------- /sdk-scd/src/main/resources/WeDPR_dynamic_lib/.blank_file: -------------------------------------------------------------------------------- 1 | Have a good day :D 2 | -------------------------------------------------------------------------------- /sdk-vcl/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | } 4 | dependencies { 5 | api project(':sdk-common') 6 | implementation project(':sdk-common') 7 | } 8 | task sourcesJar(type: Jar) { 9 | from sourceSets.main.allJava 10 | archiveClassifier = 'sources' 11 | } 12 | 13 | task javadocJar(type: Jar) { 14 | from javadoc 15 | archiveClassifier = 'javadoc' 16 | } 17 | -------------------------------------------------------------------------------- /sdk-vcl/src/main/java/com/webank/wedpr/vcl/NativeInterface.java: -------------------------------------------------------------------------------- 1 | // Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. 2 | 3 | package com.webank.wedpr.vcl; 4 | 5 | import com.webank.wedpr.common.NativeUtils; 6 | import java.io.IOException; 7 | 8 | /** Native interface for VCL client. */ 9 | public class NativeInterface { 10 | 11 | static { 12 | try { 13 | // Load the dynamic library of VCL on different operating systems. 14 | String osName = System.getProperty("os.name").toLowerCase(); 15 | String libPathInJar; 16 | if (osName.contains("windows")) { 17 | libPathInJar = "WeDPR_dynamic_lib/ffi_java_vcl.dll"; 18 | } else if (osName.contains("linux")) { 19 | libPathInJar = "WeDPR_dynamic_lib/libffi_java_vcl.so"; 20 | } else if (osName.contains("mac")) { 21 | libPathInJar = "WeDPR_dynamic_lib/libffi_java_vcl.dylib"; 22 | } else { 23 | throw new IOException( 24 | String.format("Operating system %s is not supported.", osName)); 25 | } 26 | NativeUtils.loadLibrary(libPathInJar); 27 | } catch (IOException e) { 28 | // TODO: Provide more instructions on resolving dynamic library loading errors. 29 | throw new RuntimeException(e); 30 | } 31 | } 32 | 33 | public static native VclResult makeCredit(long value); 34 | 35 | public static native VclResult proveSumBalance( 36 | String c1Secret, String c2Secret, String c3Secret); 37 | 38 | public static native VclResult verifySumBalance( 39 | String c1Credit, String c2Credit, String c3Credit, String proof); 40 | 41 | public static native VclResult proveProductBalance( 42 | String c1Secret, String c2Secret, String c3Secret); 43 | 44 | public static native VclResult verifyProductBalance( 45 | String c1Credit, String c2Credit, String c3Credit, String proof); 46 | 47 | public static native VclResult proveRange(String ownerSecret); 48 | 49 | public static native VclResult verifyRange(String confidentialCredit, String proof); 50 | } 51 | -------------------------------------------------------------------------------- /sdk-vcl/src/main/java/com/webank/wedpr/vcl/VclClient.java: -------------------------------------------------------------------------------- 1 | // Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. 2 | 3 | package com.webank.wedpr.vcl; 4 | 5 | import com.webank.wedpr.common.WedprException; 6 | 7 | /** Client class used by VCL. This is the main interface class for Java apps using VCL functions. */ 8 | public class VclClient { 9 | /** 10 | * Makes a confidential credit record and owner secret for a numeric value. 11 | * 12 | * @param value credit value. 13 | * @return VclResult containing data for confidentialCredit, ownerSecret. 14 | * @throws WedprException if any error occurred. 15 | */ 16 | public VclResult makeCredit(long value) throws WedprException { 17 | return NativeInterface.makeCredit(value).expectNoError(); 18 | } 19 | 20 | /** 21 | * Proves three confidential credit records satisfying a sum relationship, i.e. the values 22 | * embedded in them satisfying c1_value + c2_value = c3_value. c?_secret are the owner secrets 23 | * for spending those credit. 24 | * 25 | * @param c1Secret the owner secret for spending the credit of c1_value. 26 | * @param c2Secret the owner secret for spending the credit of c2_value. 27 | * @param c3Secret the owner secret for spending the credit of c3_value. 28 | * @return VclResult containing data for proof. 29 | * @throws WedprException if any error occurred. 30 | */ 31 | public VclResult proveSumBalance(String c1Secret, String c2Secret, String c3Secret) 32 | throws WedprException { 33 | return NativeInterface.proveSumBalance(c1Secret, c2Secret, c3Secret).expectNoError(); 34 | } 35 | 36 | /** 37 | * Verifies three commitments satisfying a sum relationship, i.e. the values embedded in 38 | * c1_credit, c2_credit, c3_credit satisfying c1_value + c2_value = c3_value. 39 | * 40 | * @param c1Credit the confidential credit record of c1_value. 41 | * @param c2Credit the confidential credit record of c2_value. 42 | * @param c3Credit the confidential credit record of c3_value. 43 | * @param proof the proof of satisfying the sum relationship or not. 44 | * @return VclResult containing data for verificationResult. 45 | * @throws WedprException if any error occurred. 46 | */ 47 | public VclResult verifySumBalance( 48 | String c1Credit, String c2Credit, String c3Credit, String proof) throws WedprException { 49 | return NativeInterface.verifySumBalance(c1Credit, c2Credit, c3Credit, proof) 50 | .expectNoError(); 51 | } 52 | 53 | /** 54 | * Proves three confidential credit records satisfying a product relationship, i.e. the values 55 | * embedded in them satisfying c1_value * c2_value = c3_value. c?_secret are the owner secrets 56 | * for spending those commitments. 57 | * 58 | * @param c1Secret the owner secret for spending the credit of c1_value. 59 | * @param c2Secret the owner secret for spending the credit of c2_value. 60 | * @param c3Secret the owner secret for spending the credit of c3_value. 61 | * @return VclResult containing data for proof. 62 | * @throws WedprException if any error occurred. 63 | */ 64 | public VclResult proveProductBalance(String c1Secret, String c2Secret, String c3Secret) 65 | throws WedprException { 66 | return NativeInterface.proveProductBalance(c1Secret, c2Secret, c3Secret).expectNoError(); 67 | } 68 | 69 | /** 70 | * Verifies three commitments satisfying a product relationship, i.e. the values embedded in 71 | * c1_credit, c2_credit, c3_credit satisfying c1_value * c2_value = c3_value. 72 | * 73 | * @param c1Credit the confidential credit record of c1_value. 74 | * @param c2Credit the confidential credit record of c2_value. 75 | * @param c3Credit the confidential credit record of c3_value. 76 | * @param proof the proof of satisfying the product relationship or not. 77 | * @return VclResult containing data for verificationResult. 78 | * @throws WedprException if any error occurred. 79 | */ 80 | public VclResult verifyProductBalance( 81 | String c1Credit, String c2Credit, String c3Credit, String proof) throws WedprException { 82 | return NativeInterface.verifyProductBalance(c1Credit, c2Credit, c3Credit, proof) 83 | .expectNoError(); 84 | } 85 | 86 | /** 87 | * Proves whether the value embedded in a confidential credit record belongs to (0, 88 | * 2^RANGE_SIZE_IN_BITS - 1]. RANGE_SIZE_IN_BITS is defined in the dynamic library of VCL, whose 89 | * typical value is 32. 90 | * 91 | * @param ownerSecret the owner secret for spending a credit. 92 | * @return VclResult containing data for proof. 93 | * @throws WedprException if any error occurred. 94 | */ 95 | public VclResult proveRange(String ownerSecret) throws WedprException { 96 | return NativeInterface.proveRange(ownerSecret).expectNoError(); 97 | } 98 | 99 | /** 100 | * Verifies whether the value embedded in a confidential credit record belongs to (0, 101 | * 2^RANGE_SIZE_IN_BITS - 1]. RANGE_SIZE_IN_BITS is defined in the dynamic library of VCL, whose 102 | * typical value is 32. 103 | * 104 | * @param confidentialCredit the confidential credit record of a value. 105 | * @param proof the proof of satisfying the range constraint or not. 106 | * @return VclResult containing data for verificationResult. 107 | * @throws WedprException if any error occurred. 108 | */ 109 | public VclResult verifyRange(String confidentialCredit, String proof) throws WedprException { 110 | return NativeInterface.verifyRange(confidentialCredit, proof).expectNoError(); 111 | } 112 | 113 | // TODO: Add a getVclConfig function to expose the value of RANGE_SIZE_IN_BITS. 114 | } 115 | -------------------------------------------------------------------------------- /sdk-vcl/src/main/java/com/webank/wedpr/vcl/VclResult.java: -------------------------------------------------------------------------------- 1 | // Copyright 2020 WeDPR Lab Project Authors. Licensed under Apache-2.0. 2 | 3 | package com.webank.wedpr.vcl; 4 | 5 | import com.webank.wedpr.common.WedprException; 6 | import com.webank.wedpr.common.WedprResult; 7 | 8 | /** 9 | * Result class used by VCL client. 10 | * 11 | *

This is an easy way to return multiple data from a single JNI interface. 12 | */ 13 | public class VclResult extends WedprResult { 14 | public String confidentialCredit; 15 | public String ownerSecret; 16 | public String proof; 17 | public boolean verificationResult; 18 | 19 | /** Expects no error occurred, otherwise throws an Exception. */ 20 | public VclResult expectNoError() throws WedprException { 21 | if (hasError()) { 22 | throw new WedprException(wedprErrorMessage); 23 | } 24 | return this; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /sdk-vcl/src/main/resources/WeDPR_dynamic_lib/.blank_file: -------------------------------------------------------------------------------- 1 | Have a good day :D 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * This file was generated by the Gradle 'init' task. 3 | * 4 | * The settings file is used to specify which projects to include in your build. 5 | * 6 | * Detailed information about configuring a multi-project build in Gradle can be found 7 | * in the user manual at https://docs.gradle.org/6.6.1/userguide/multi_project_builds.html 8 | */ 9 | 10 | rootProject.name = 'WeDPR-Lab-Java-SDK' 11 | include 'sdk-common' 12 | include 'sdk-crypto' 13 | include 'sdk-vcl' 14 | include 'sdk-scd' 15 | include 'sdk-ktb' 16 | include 'sdk-acv' 17 | include "sdk-demo" 18 | --------------------------------------------------------------------------------