Skip to content

Commit

Permalink
store private keys in hex format
Browse files Browse the repository at this point in the history
so we can read them from java and any other potential language that we
want to support and test
  • Loading branch information
ecioppettini committed Jul 29, 2021
1 parent 129a7b9 commit 3946c25
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 25 deletions.
26 changes: 11 additions & 15 deletions bindings/wallet-jni/java/WalletTest.java
Expand Up @@ -19,25 +19,21 @@
import static org.junit.Assert.assertNotEquals;

public class WalletTest {
private byte[] accountKey() {
final byte[] accountKey = { -56, 101, -106, -62, -47, 32, -120, -123, -37, 31, -29, 101, -124, 6, -86, 15, 124,
-57, -72, -31, 60, 54, 47, -28, 106, 109, -78, 119, -4, 80, 100, 88, 62, 72, 117, -120, -55, -118, 108,
54, -30, -25, 68, 92, 10, -35, 54, -8, 63, 23, 28, -75, -52, -3, -127, 85, 9, -47, -100, -45, -114, -53,
10, -13, };
private byte[] accountKey() throws IOException{
final String accountKey = new String(
Files.readAllBytes(Paths.get("../../../test-vectors/free_keys/key1.prv"))).trim();

return accountKey;
return hexStringToByteArray(accountKey);
}

private byte[] utxoKeys() {
final byte[] utxoKeys = { 48, 21, 89, -52, -78, -44, -52, 126, -98, 84, -90, -11, 90, -128, -106, 11, -74, -111,
-73, -79, 64, -107, 73, -17, -122, -107, -87, 46, -92, 26, 111, 79, 64, 82, 49, -88, 6, -62, -25, -71,
-48, -37, 48, -31, 94, -32, -52, 31, 38, 28, 27, -97, -106, 21, 99, 107, 72, -67, -119, -2, 123, -26,
-22, 31, -88, -74, -67, -16, -128, -57, 79, -68, 49, 51, 126, -34, 75, 102, -110, -62, -21, -19, 126,
52, -81, 109, -104, -73, -69, -51, 71, -116, -16, 123, 13, 94, -39, 63, 126, -99, 74, -93, -81, -34, 50,
26, -31, -85, -74, 27, -125, 68, -62, 67, -55, -48, -76, 7, -53, -8, -111, 125, -74, -33, 44, 101, 61,
-22, };
private byte[] utxoKeys() throws IOException{
final String utxoKey1 = new String(
Files.readAllBytes(Paths.get("../../../test-vectors/free_keys/key2.prv"))).trim();

final String utxoKey2 = new String(
Files.readAllBytes(Paths.get("../../../test-vectors/free_keys/key3.prv"))).trim();

return utxoKeys;
return hexStringToByteArray(utxoKey1.concat(utxoKey2));
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion test-vectors/free_keys/key1.prv
@@ -1 +1 @@
ed25519e_sk1epjedsk3yzygtkcludjcgp42pa7v0w8p8smzler2dke80lzsv3vrujr43ryc5mpkutn5ghq2m5m0s0chrj6uelvp25yar8xn3m9s4ucseta6n
c86596c2d1208885db1fe3658406aa0f7cc7b8e13c362fe46a6db277fc5064583e487588c98a6c36e2e7445c0add36f83f171cb5ccfd815509d19cd38ecb0af3
2 changes: 1 addition & 1 deletion test-vectors/free_keys/key2.prv
@@ -1 +1 @@
ed25519e_sk1xq24nn9j6nx8a8j55m644qykpwmfrda3gz25nmuxjk5jafq6da85q5334qrv9eae6rdnpc27urxp7fsurw0ev9trddytmz0700nw58c0du7tw
301559ccb2d4cc7e9e54a6f55a80960bb691b7b1409549ef8695a92ea41a6f4f405231a806c2e7b9d0db30e15ee0cc1f261c1b9f9615636b48bd89fe7be6ea1f
2 changes: 1 addition & 1 deletion test-vectors/free_keys/key3.prv
@@ -1 +1 @@
ed25519e_sk14zmtmuyqca8mcvfn0m0yke5jct476l354ake3dame4rceurmp40dj0m7n4928t77xgdwr2akrwp5fsjre8gtgp7tlzghmdkl93jnm6sls9x94
a8b6bdf080c74fbc31337ede4b6692c2ebed7e34af6d98b7bbcd478cf07b0d5ed93f7e9d4aa3afde321ae1abb61b8344c243c9d0b407cbf8917db6df2c653dea
10 changes: 8 additions & 2 deletions wallet/tests/account.rs
@@ -1,7 +1,7 @@
mod utils;

use self::utils::State;
use chain_crypto::{bech32::Bech32, SecretKey};
use chain_crypto::SecretKey;
use chain_impl_mockchain::{
certificate::VoteCast,
fragment::Fragment,
Expand Down Expand Up @@ -35,7 +35,12 @@ fn update_state_overrides_old() {
fn cast_vote() {
let mut account = wallet::RecoveryBuilder::new()
.account_secret_key(
SecretKey::try_from_bech32_str(String::from(ACCOUNT_KEY).trim()).unwrap(),
SecretKey::from_binary(
hex::decode(String::from(ACCOUNT_KEY).trim())
.unwrap()
.as_ref(),
)
.unwrap(),
)
.build_wallet()
.expect("recover account");
Expand All @@ -45,6 +50,7 @@ fn cast_vote() {

for fragment in state.initial_contents() {
account.check_fragment(&fragment.hash(), fragment);
account.confirm(&fragment.hash());
}

let vote_plan_id: [u8; 32] = hex::decode(
Expand Down
18 changes: 13 additions & 5 deletions wallet/tests/free_keys.rs
@@ -1,7 +1,7 @@
mod utils;

use self::utils::State;
use chain_crypto::{bech32::Bech32, SecretKey};
use chain_crypto::SecretKey;
use chain_impl_mockchain::value::Value;
use wallet::transaction::dump_free_utxo;

Expand All @@ -15,11 +15,16 @@ const WALLET_VALUE: Value = Value(10_000 + 1000);
fn test_free_utxo_key_dump() {
let builder = wallet::RecoveryBuilder::new();

let builder = builder
.account_secret_key(SecretKey::try_from_bech32_str(String::from(ACCOUNT).trim()).unwrap());
let builder = builder.account_secret_key(
SecretKey::from_binary(hex::decode(String::from(ACCOUNT).trim()).unwrap().as_ref())
.unwrap(),
);

let builder = [UTXO1, UTXO2].iter().fold(builder, |builder, key| {
builder.add_key(SecretKey::try_from_bech32_str(String::from(*key).trim()).unwrap())
builder.add_key(
SecretKey::from_binary(hex::decode(String::from(*key).trim()).unwrap().as_ref())
.unwrap(),
)
});

let mut free_keys = builder.build_free_utxos().unwrap();
Expand All @@ -33,9 +38,12 @@ fn test_free_utxo_key_dump() {
for fragment in state.initial_contents() {
account.check_fragment(&fragment.hash(), fragment);
free_keys.check_fragment(&fragment.hash(), fragment);

account.confirm(&fragment.hash());
free_keys.confirm(&fragment.hash());
}

assert_eq!(free_keys.unconfirmed_value(), Some(WALLET_VALUE));
assert_eq!(free_keys.confirmed_value(), WALLET_VALUE);

let (fragment, ignored) = dump_free_utxo(&settings, &address, &mut free_keys)
.next()
Expand Down

0 comments on commit 3946c25

Please sign in to comment.