Unverified Commit bff95cbc authored by Hanwen Cheng's avatar Hanwen Cheng Committed by GitHub
Browse files

test: signing with seed reference (#582)



* Decrypt and sign without seed crossing bridge

- decrypt the seed in rust and return a raw pointer as i64
- from ios return int64_t
- from android return double using Double.longBitsToDouble
- in typescript use number
- sign messages by passing the seed reference and converting back to a
String pointer in rust

* Remove debug code

* lint

* lint fixes

* test: rust signing with ref

* remove malloc test
Co-authored-by: default avatarJoseph Mark <sjeohp@gmail.com>
parent ffa23843
Pipeline #86021 failed with stages
in 3 minutes and 48 seconds
......@@ -23,7 +23,7 @@
"start": "NODE_OPTIONS=--max_old_space_size=8192 npx react-native start",
"unit": "jest --config ./test/unit/jest.config.js",
"unit:debug": "node --inspect node_modules/.bin/jest --config ./test/unit/jest.config.js --watch --runInBand",
"test-rust": "cd ./rust/signer && cargo test && cd ../..",
"test-rust": "(cd ./rust/signer && cargo test)",
"build-e2e:android": "detox build -c android.emu.debug -l info",
"test-e2e:android": "detox test -c android.emu.debug -l info --noStackTrace",
"e2e:android": "yarn run build-e2e:android && yarn run test-e2e:android",
......
......@@ -235,7 +235,7 @@ export! {
let password = Protected::new(password.into_bytes());
let crypto: Crypto = serde_json::from_str(data).ok()?;
let decrypted = crypto.decrypt(&password).ok()?;
let res = Box::into_raw(Box::new(String::from_utf8(decrypted).ok())) as i64;
let res = Box::into_raw(Box::new(String::from_utf8(decrypted).ok())) as i64;
Some(res)
}
......@@ -278,8 +278,9 @@ mod tests {
use super::*;
static SURI: &str = "grant jaguar wish bench exact find voice habit tank pony state salmon";
static DERIVED_SURI: &str = "grant jaguar wish bench exact find voice habit tank pony state salmon//hard/soft/0";
static ENCRYPTED_SEED: &str = "{\"cipher\":\"aes-128-ctr\",\"cipherparams\":{\"iv\":\"47b4b75d13045ff7569da858e234f7ea\"},\"ciphertext\":\"ca1cf5387822b70392c4aeec729676f91ab00a795d7593fb7e52ecc333dbc4a1acbedc744b5d8d519c714e194bd741995244c8128bfdce6c184d6bda4ca136ed265eedcee9\",\"kdf\":\"pbkdf2\",\"kdfparams\":{\"c\":10240,\"dklen\":32,\"prf\":\"hmac-sha256\",\"salt\":\"b4a2d1edd1a70fe2eb48d7aff15c19e234f6aa211f5142dddb05a59af12b3381\"},\"mac\":\"b38a54eb382f2aa1a8be2f7b86fe040fe112d0f42fea03fac186dccdd7ae3eb9\"}";
static PIN: &str = "000000";
#[test]
fn test_random_phrase() {
......@@ -288,7 +289,7 @@ mod tests {
let result_24 = random_phrase(24);
assert_eq!(24, result_24.split_whitespace().count());
let result_17 = random_phrase(17);
assert_eq!(12, result_17.split_whitespace().count());
assert_eq!(24, result_17.split_whitespace().count());
}
#[test]
......@@ -341,4 +342,21 @@ mod tests {
assert!(is_valid);
}
#[test]
fn test_substrate_sign_with_ref() {
let msg: String = b"Build The Future".to_hex();
let data_pointer = decrypt_data_ref(ENCRYPTED_SEED, String::from(PIN)).unwrap();
let signature_by_ref = substrate_brainwallet_sign_with_ref(data_pointer, &msg).unwrap();
let is_valid = schnorrkel_verify(SURI, &msg, &signature_by_ref).unwrap();
destroy_data_ref(data_pointer);
assert!(is_valid);
}
#[test]
fn decrypt_with_ref() {
let decrypted_result = decrypt_data(ENCRYPTED_SEED, String::from(PIN)).unwrap();
assert_eq!(SURI, decrypted_result);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment