Skip to content

Commit

Permalink
encrypted wallet objectMapper format bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
skywills committed Oct 7, 2020
1 parent 6e5e690 commit 90c3f52
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/main/java/com/mxw/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public Wallet(SigningKey privateKey, Provider provider, TransactionManager trans
this.signingKey = privateKey;
this.provider = provider;
this.transactionManager = transactionManager;
this.objectMapper = ObjectMapperFactory.getObjectMapper();
this.objectMapper = new ObjectMapper();
}

@Override
Expand Down Expand Up @@ -203,12 +203,12 @@ public void setSigningKey(SigningKey signingKey) {
this.signingKey = signingKey;
}

public WalletFile EncryptWallet(String password) throws CipherException {
public WalletFile encryptWallet(String password) throws CipherException {
return SecretStorage.createEncryptedWallet(password, this.signingKey);
}

public String EncryptWalletJson(String password) throws CipherException, JsonProcessingException {
WalletFile walletFile = EncryptWallet(password);
public String encryptWalletJson(String password) throws CipherException, JsonProcessingException {
WalletFile walletFile = encryptWallet(password);
return objectMapper.writeValueAsString(walletFile);
}

Expand Down
24 changes: 24 additions & 0 deletions src/test/java/com/mxw/Test0100Kyc.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mxw;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.mxw.crypto.Keys;
import com.mxw.crypto.SecretStorage;
Expand Down Expand Up @@ -70,6 +71,29 @@ public void testGenerateKycAddress() throws Exception {
Assert.assertEquals(computedKycAddress,"kyc1v6kf4scf6pctpqxsqua5wwldn7lqh2cxc0vs924a3aywgf80z3ests6dc2");
}

@Test
public void printKycToSign() throws Exception {
System.out.println("Begin whitelist ... ");

String country = "MY";
String idType = "NIC";
String id = userWallet.getAddress();
int idExpiry = 20200101;
int dob = 19800101;
byte[] seed = SecretStorage.generateRandomBytes(32);

BigInteger nonce = this.jsonRpcProvider.getTransactionCount(userWallet.getAddress());

KycAddress kycAddress = new KycAddress(country, idType, id, idExpiry, dob, Address.getHash(seed).toLowerCase());
String kycAddressHash = Keys.getKeyAddressHex(this.objectMapper.writeValueAsString(kycAddress));
String computedKycAddress = Keys.computeKycAddress(kycAddressHash,Constants.kycAddressPrefix);
KycWhitelistModel kycWhitelistModel = new KycWhitelistModel(userWallet.getAddress(), computedKycAddress, nonce);
System.out.println(objectMapper.writeValueAsString(kycWhitelistModel));
PublicKey kycPubKey = new PublicKey("tendermint/" + userWallet.getPublicKeyType(), Base64s.base16to64(userWallet.getCompressedPublicKey()));
KycWhitelistPayload kycWhitelistPayload = new KycWhitelistPayload(kycWhitelistModel, kycPubKey, userWallet.getSignature(kycWhitelistModel).getSignature());
System.out.println(objectMapper.writeValueAsString(kycWhitelistPayload));
}

@Test
public void testKyc() throws Exception {

Expand Down

0 comments on commit 90c3f52

Please sign in to comment.