Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zo-el committed May 29, 2024
1 parent 1feccc9 commit 530fc4b
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 30 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 11 additions & 9 deletions core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use arrayref::array_ref;
use ed25519_dalek::*;
use failure::Error;
use serde::*;

use crate::public_key;
pub const SEED_SIZE: usize = 32;

fn public_key_from_base64<'de, D>(deserializer: D) -> Result<PublicKey, D::Error>
Expand Down Expand Up @@ -77,12 +79,12 @@ pub enum Config {
/// This is the Device Seed Bundle as a base64 string which is compatible with lair-keystore >=v0.0.8
/// And is encoded with a password that will be needed to be used to decrypt it
device_bundle: String,
// The revocation key is usually the /0 derivation path of the master seed
revocation_pub_key: String,
// /1 derivation path of the device bundle
holoport_id: PublicKey,
/// Derivation path of the seed in this config that was generated for a Master Seed
derivation_path: String,
device_derivation_path: String,
// The revocation key is usually the /0 derivation path of the master seed
revocation_pub_key: PublicKey,
// /1 derivation path of the device bundle base36 encoded
holoport_id: String,
/// Holo registration code is used to identify and authenticate its users
registration_code: String,
/// The pub-key in settings is the holoport key that is used for verifying login signatures
Expand All @@ -95,9 +97,8 @@ impl Config {
email: String,
password: String,
registration_code: String,
revocation_pub_key: String,
holoport_id: PublicKey,
derivation_path: String,
revocation_pub_key: PublicKey,
device_derivation_path: String,
device_bundle: String,
device_pub_key: PublicKey,
) -> Result<(Self, PublicKey), Error> {
Expand All @@ -106,10 +107,11 @@ impl Config {
email: email,
public_key: admin_keypair.public,
};
let holoport_id = public_key::to_base36_id(&device_pub_key);
Ok((
Config::V3 {
device_bundle,
derivation_path,
device_derivation_path,
revocation_pub_key,
holoport_id,
registration_code,
Expand Down
4 changes: 1 addition & 3 deletions gen-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ struct Args {
flag_email: String,
flag_password: String,
flag_registration_code: String,
flag_revocation_pub_key: String,
flag_holoport_id: PublicKey,
flag_revocation_pub_key: PublicKey,
flag_derivation_path: String,
flag_device_bundle: String,
flag_seed_from: Option<PathBuf>,
Expand Down Expand Up @@ -59,7 +58,6 @@ fn main() -> Result<(), Error> {
args.flag_password,
args.flag_registration_code,
args.flag_revocation_pub_key,
args.flag_holoport_id,
args.flag_derivation_path,
args.flag_device_bundle,
PublicKey::from(&secret_key),
Expand Down
10 changes: 3 additions & 7 deletions gen-web/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,19 @@ fn config_raw(
email: String,
password: String,
registration_code: String,
revocation_pub_key: String,
holoport_id: Vec<u8>,
revocation_pub_key: Vec<u8>,
derivation_path: String,
device_bundle: String,
device_pub_key: String,
) -> Result<JsValue, Error> {
let device_pub_key: PublicKey = base64::decode_config(&device_pub_key, base64::URL_SAFE_NO_PAD)
.map(|bytes| PublicKey::from_bytes(&bytes))??;
let holoport_id = PublicKey::from_bytes(&holoport_id)?;
let revocation_pub_key = PublicKey::from_bytes(&revocation_pub_key)?;
let (config, public_key) = Config::new(
email,
password,
registration_code,
revocation_pub_key,
holoport_id,
derivation_path,
device_bundle,
device_pub_key,
Expand All @@ -50,8 +48,7 @@ pub fn config(
email: String,
password: String,
registration_code: String,
revocation_pub_key: String,
holoport_id: Vec<u8>,
revocation_pub_key: Vec<u8>,
derivation_path: String,
device_bundle: String,
device_pub_key: String,
Expand All @@ -61,7 +58,6 @@ pub fn config(
password,
registration_code,
revocation_pub_key,
holoport_id,
derivation_path,
device_bundle,
device_pub_key,
Expand Down
2 changes: 1 addition & 1 deletion into-base36-id/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async fn main() -> Result<()> {
println!("{}", public_key::to_base36_id(&public));
}
Config::V3 { holoport_id, .. } => {
println!("{}", public_key::to_base36_id(&holoport_id));
println!("{}", holoport_id);
}
}

Expand Down
3 changes: 3 additions & 0 deletions seed-bundle-explorer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ edition = "2021"
repository = "https://github.com/Holo-Host/hpos-config"

[dependencies]
base36 = "0.0.1"
base64 = "0.13.0"
ed25519-dalek = { version = "1", features = ["serde"] }
hpos-config-core = { path = "../core" }
Expand All @@ -20,3 +21,5 @@ one_err = "0.0.8"

[dev-dependencies]
tokio = { version = "1.12.0", features = [ "full" ] }
hc_seed_bundle = "0.1.5"
base64 = "0.13.0"
13 changes: 13 additions & 0 deletions seed-bundle-explorer/src/jasd.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"device_bundle": "k6VoY3NiMJGWonB3xBCZ0R47aR6ctMScaYsrOLwRzSAAAcQY58NsOmNCDbniGsLgUhj5UoHjBrapiiDGxDGAa5Wqzm0pVuXGN106iyMHRk4dOf0iGWj65oCeB8-ZYXJdeflsVDY-DOuJaadfPZQExCyCrWRldmljZV9udW1iZXIAq2dlbmVyYXRlX2J5r3F1aWNrc3RhcnQtdjIuMA",
"revocation_pub_key": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"holoport_id": "4099r424lmhpjhqsrf253fq8pkuladttqq0k1vkf96bsiy9lnf",
"derivation_path": "1",
"registration_code": "registration-code",
"settings": {
"admin": {
"email": "[email protected]",
"public_key": [215, 40, 133, 123, 179, 96, 208, 91, 185, 17, 99, 109, 188, 70, 164, 254, 138, 105, 60, 69, 42, 100, 13, 34, 166, 178, 194, 10, 192, 50, 23, 208]
}
}
}
5 changes: 4 additions & 1 deletion seed-bundle-explorer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ pub async fn holoport_public_key(
let Keypair { public, .. } = unlock(device_bundle, passphrase).await?;
Ok(public)
}
Config::V3 { holoport_id, .. } => Ok(holoport_id.to_owned()),
Config::V3 { holoport_id, .. } => {
let value = base36::decode(&holoport_id).unwrap();
Ok(PublicKey::from_bytes(&value)?)
}
}
}

Expand Down
16 changes: 7 additions & 9 deletions seed-bundle-explorer/tests/explorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ mod tests {
email,
password,
registration_code,
"revocation_pub_key".to_string(),
PublicKey::from_bytes(&vec![0; 32]).unwrap(),
PublicKey::from_bytes([0; 32].as_ref()).unwrap(),
derivation_path,
device_bundle,
get_mock_pub_key()?,
Expand All @@ -34,12 +33,11 @@ mod tests {
Ok(config)
}
fn get_mock_pub_key() -> Result<PublicKey, String> {
let device_pub_key: String = "To4PzBU8BcVghpjGjnYjLQnP_mkT9uBJ2v969Cs7-xw".to_string();
Ok(
base64::decode_config(&device_pub_key, base64::URL_SAFE_NO_PAD)
.map(|bytes| PublicKey::from_bytes(&bytes))
.unwrap()
.unwrap(),
)
let device_pub_key: String =
"4099r424lmhpjhqsrf253fq8pkuladttqq0k1vkf96bsiy9lnf".to_string();
Ok(base36::decode(&device_pub_key)
.map(|bytes| PublicKey::from_bytes(&bytes))
.unwrap()
.unwrap())
}
}

0 comments on commit 530fc4b

Please sign in to comment.