Skip to content
This repository was archived by the owner on Aug 12, 2021. It is now read-only.

Commit 08a9dbd

Browse files
authored
fix bug: random key pair error (#28)
* fix bug : random keypair error * bump version * fix nettify
1 parent f849f0f commit 08a9dbd

11 files changed

Lines changed: 92 additions & 40 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 1.0.6 (December 31, 2019)
2+
- fix bug: random wallet generate error
3+
14
## 1.0.5 (December 24, 2019)
25
- fix bug: gql cache remove
36
- change itx type from string to json

build.gradle

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
buildscript{
2-
if (!System.getenv("SONATYPE_USERNAME").isEmpty()){
2+
if (System.getenv("SONATYPE_USERNAME") != null){
33
ext."sonatypeUsername" = System.getenv("SONATYPE_USERNAME")
44
ext."sonatypePassword" = System.getenv("SONATYPE_PASSWORD")
55
}
6+
if(project.findProperty("sonatypeUsername") == null){
7+
ext.sonatypeUsername = ""
8+
ext.sonatypePassword = ""
9+
}
610
}
711
allprojects {
812
buildscript {
@@ -33,38 +37,32 @@ allprojects {
3337

3438

3539
gradle.taskGraph.whenReady { taskGraph ->
36-
if (!System.getenv('GPG_KEY_ID').isEmpty() && taskGraph.allTasks.any { it instanceof Sign }) {
40+
if (taskGraph.allTasks.any { it instanceof Sign }) {
3741
// Use Java's console to read from the console (no good for
3842
// a CI environment)
39-
def id = System.getenv('GPG_KEY_ID')
40-
def file = "../secring.gpg"
41-
def password = System.getenv('GPG_KEY_PASSPHRASE')
42-
43-
allprojects {
44-
ext."signing.keyId" = id
45-
ext."signing.secretKeyRingFile" = file
46-
ext."signing.password" = password
43+
if(System.getenv('GPG_KEY_ID') != null){
44+
def id = System.getenv('GPG_KEY_ID')
45+
def file = "../secring.gpg"
46+
def password = System.getenv('GPG_KEY_PASSPHRASE')
47+
48+
allprojects {
49+
ext."signing.keyId" = id
50+
ext."signing.secretKeyRingFile" = file
51+
ext."signing.password" = password
52+
53+
ext.sonatypeUsername = System.getenv("SONATYPE_USERNAME")
54+
ext.sonatypePassword = System.getenv("SONATYPE_PASSWORD")
55+
}
56+
}
4757

48-
ext.sonatypeUsername = System.getenv("SONATYPE_USERNAME")
49-
ext.sonatypePassword = System.getenv("SONATYPE_PASSWORD")
5058

51-
}
5259
}
5360
}
5461

5562

5663
}
5764
apply plugin: 'signing'
5865

59-
subprojects {
60-
61-
62-
// signing.keyId=System.getenv('GPG_KEY_ID')
63-
// signing.password=System.getenv('GPG_KEY_PASSPHRASE')
64-
// signing.secretKeyRingFile="/Users/paperhuang/.gnupg/secring.gpg"
65-
66-
67-
}
6866

6967

7068

core/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ sourceSets {
2828

2929
}
3030
test {
31-
kotlin { srcDir "src/test/kotlin" }
31+
kotlin { srcDir ("src/test/kotlin",) }
3232
java { srcDir "src/test/java" }
3333

3434
}
@@ -109,7 +109,7 @@ dependencies {
109109
implementation ("javax.validation:validation-api:2.0.1.Final")
110110
compile 'org.apache.commons:commons-lang3:3.4'
111111
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
112-
112+
testCompile project(':protobuf')
113113
testImplementation 'ch.qos.logback:logback-classic:1.2.3'
114114
testCompile group: 'junit', name: 'junit', version: '4.12'
115115
testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"

core/src/main/java/io/arcblock/forge/did/DIDGenerator.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,11 @@ object DIDGenerator {
186186
WalletInfo {
187187
val type = if (walletType == null) Type.WalletType.newBuilder().setHash(Enum.HashType.sha3).setPk(Enum.KeyType.ed25519).setRole(Enum.RoleType
188188
.role_account).build() else walletType
189-
val seed =Bip44Utils.genSeed(UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString())
190-
val sk= Bip44Utils.genKeyPair(seed).privateKey.toByteArray()
189+
var sk :ByteArray = ByteArray(0)
190+
while (sk.size < 32){
191+
val seed =Bip44Utils.genSeed(UUID.randomUUID().toString(),UUID.randomUUID().toString(),UUID.randomUUID().toString())
192+
sk= Bip44Utils.genKeyPair(seed).privateKey.toByteArray()
193+
}
191194
return WalletInfo(sk=sk,pk = WalletUtils.sk2pk(sk= sk, keyType = type.pk),address = sk2did( RoleType.fromInt(type.roleValue),KeyType.fromInt(type.pkValue),
192195
HashType.fromInt(type.hashValue),sk).address())
193196
}

core/src/test/kotlin/io/arcblock/forge/did/DIDGeneratorTest.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.google.common.io.BaseEncoding
44
import com.google.protobuf.Any
55
import com.google.protobuf.ByteString
66
import forge_abi.CreateAsset
7+
78
import io.arcblock.forge.Hasher
89
import io.arcblock.forge.WalletUtils
910
import io.arcblock.forge.bip44.Bip44Utils
@@ -14,8 +15,10 @@ import io.arcblock.forge.getPK
1415
import org.junit.Assert
1516
import org.junit.Before
1617
import org.junit.Test
18+
import org.junit.runner.RunWith
19+
import org.junit.runners.JUnit4
1720
import org.web3j.crypto.ECKeyPair
18-
21+
@RunWith(JUnit4::class)
1922
class DIDGeneratorTest {
2023
lateinit var kp: DidKeyPair
2124

@@ -166,4 +169,11 @@ class DIDGeneratorTest {
166169

167170
}
168171

172+
@Test
173+
fun testRandomWallet(){
174+
(0..5000).forEach {
175+
DIDGenerator.randomWallet()
176+
}
177+
}
178+
169179
}

did/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ repositories {
6363
}
6464

6565
dependencies {
66-
api project(':core')
66+
compile project(':core')
6767
//implementation "io.arcblock.forge:core:$project.version"
6868
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
6969
testCompile group: 'junit', name: 'junit', version: '4.12'

examples/javademo/pom.xml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,27 @@
88
<version>1.0-SNAPSHOT</version>
99

1010
<dependencies>
11+
1112
<dependency>
1213
<groupId>io.arcblock.forge</groupId>
1314
<artifactId>core</artifactId>
14-
<version>1.0.4</version>
15+
<version>1.0.5</version>
1516
</dependency>
1617
<dependency>
1718
<groupId>io.arcblock.forge</groupId>
1819
<artifactId>did</artifactId>
19-
<version>1.0.4</version>
20+
<version>1.0.5</version>
2021
</dependency>
2122
<dependency>
2223
<groupId>io.arcblock.forge</groupId>
2324
<artifactId>graphql</artifactId>
24-
<version>1.0.4</version>
25+
<version>1.0.5</version>
26+
</dependency>
27+
<dependency>
28+
<groupId>com.madgag.spongycastle</groupId>
29+
<artifactId>prov</artifactId>
30+
<version>1.58.0.0</version>
2531
</dependency>
26-
2732
<dependency>
2833
<groupId>org.slf4j</groupId>
2934
<artifactId>slf4j-api</artifactId>
@@ -34,7 +39,11 @@
3439
<artifactId>logback-classic</artifactId>
3540
<version>1.2.3</version>
3641
</dependency>
37-
42+
<dependency>
43+
<groupId>org.jetbrains.kotlin</groupId>
44+
<artifactId>kotlin-stdlib</artifactId>
45+
<version>1.3.61</version>
46+
</dependency>
3847
</dependencies>
3948

4049

examples/javademo/src/main/java/Asset.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import java.util.UUID;
2-
31
import forge_abi.Enum;
42
import forge_abi.Rpc;
53
import io.arcblock.forge.Result;
@@ -27,8 +25,18 @@ public static void main(String[] args){
2725
response=forge.declare("Thomas", Thomas);
2826

2927
//create Asset for Thomas
30-
Result result = forge.createAsset("json",("{\"a\":"+ UUID
31-
.randomUUID().toString() +"}").getBytes(), "testAsset", Thomas);
28+
// Result result = forge.createAsset("json",("{\"a\":"+ UUID
29+
// .randomUUID().toString() +"}").getBytes(), "testAsset", Thomas);
30+
Result result = forge.createAsset("json",("{\"a\":"+
31+
"abcd" +"}").getBytes(), "testAsset", Thomas);
32+
forge_abi.Type.ChainInfo lazyChainInfo = forge.getLazyChainInfo().getValue();
33+
logger.info(lazyChainInfo.toString());
34+
35+
result = forge.createAsset("json",
36+
"cd74fb7e0c6d646056649e4c325dfa032f89adbd4007c4b753a6afb8c1d4f800287608c38e21e561ee9524cea3bedce0f0c15f099459ec02c23f7bc5b72409b86013aa58a70768f06f45523cfbaecae556e86212a76358a1ca452ac53f742e878e732598837a916e41ea8e698fbf024a61331023fbc183dd77e754cee30a8a9d1a7a014677fbc8861ac265eb1ca1f06c5f768c1bf4c01cccd15621c0d6938677327a3f9a41ab6b865a9ef80bb43b746b87f7a4db2086c9f29774a3c20a7b827a0da02d3aa78623e780bd072028d473d46a8e01df2b4bdc68187bc41ebcff73f64f1031b48d87ea8f18eee93e84dc5c09e01c44a1e6d5488220e23eb4edd297b8635e4622e256f44d503cd6e680f709403c4596c8bcf06f2431d3cba924bb408f136be10e5c444db4dedeeaa7665158850d2198d987b3e2f21c64d3b9ddfb7deadcc1816addcf6fd56df3001d6ebf1ff0cc06af0edbb23d45de7031d0e860f444ebfcd2b2a94928ed15efe6fd0b16423ebd9191a479b79bd46fbbc0c18b73b5be".getBytes(), "unsupportdata",Thomas);
37+
38+
forge_abi.Type.ChainInfo info = forge.getChainInfo().getInfo();
39+
logger.info(info.toString());
3240
response = result.getResponse();//create asset transaction response
3341
String assetAddress = result.getAddress();
3442

examples/javademo/src/main/java/BaseConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
class BaseConfig {
2626

2727
public static Logger logger = LoggerFactory.getLogger("Forge");
28-
public static Integer serverPort= 28212;
28+
public static Integer serverPort= 27210;
2929
static ObjectMapper mapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
30-
static GraphQLClient gql = new GraphQLClient("http://localhost:8212/api");
30+
static GraphQLClient gql = new GraphQLClient("http://localhost:8210/api");
3131
static ForgeSDK forge = ForgeSDK.Companion.connect("localhost", BaseConfig.serverPort);
3232
//wait for block commit
3333
static void waitForBlockCommit() {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import io.arcblock.forge.did.WalletInfo;
2+
import io.arcblock.forge.extension.StringExtensionKt;
3+
4+
/**
5+
* Author : shan@arcblock.io
6+
* Time : 2019-12-26
7+
* Edited By :
8+
* Edited Time :
9+
* Description :
10+
**/
11+
class RandowmWallet extends BaseConfig{
12+
public static void main(String[] args){
13+
WalletInfo alice = forge.createWallet();
14+
logPretty(alice);
15+
16+
logger.info("alice sk:"+ StringExtensionKt.encodeB64(alice.getSk()));
17+
18+
WalletInfo cc = WalletInfo.Companion.fromSk(alice.getSk());
19+
logPretty(cc);
20+
}
21+
}

0 commit comments

Comments
 (0)