Skip to content

Commit

Permalink
refactoring and renaming sk_iss to imk throughout the project
Browse files Browse the repository at this point in the history
  • Loading branch information
vivek-arte committed Oct 13, 2023
1 parent 7937e5b commit 64d4ed1
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
8 changes: 4 additions & 4 deletions src/issuance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,8 +629,8 @@ mod tests {
) {
let mut rng = OsRng;

let sk_iss = IssuanceKey::random(&mut rng);
let isk: IssuanceAuthorizingKey = (&sk_iss).into();
let imk = IssuanceKey::random(&mut rng);
let isk: IssuanceAuthorizingKey = (&imk).into();
let ik: IssuanceValidatingKey = (&isk).into();

let fvk = FullViewingKey::from(&SpendingKey::random(&mut rng));
Expand Down Expand Up @@ -1278,8 +1278,8 @@ mod tests {

let mut signed = bundle.prepare(sighash).sign(rng, &isk).unwrap();

let incorrect_sk_iss = IssuanceKey::random(&mut rng);
let incorrect_isk: IssuanceAuthorizingKey = (&incorrect_sk_iss).into();
let incorrect_imk = IssuanceKey::random(&mut rng);
let incorrect_isk: IssuanceAuthorizingKey = (&incorrect_imk).into();
let incorrect_ik: IssuanceValidatingKey = (&incorrect_isk).into();

// Add "bad" note
Expand Down
22 changes: 11 additions & 11 deletions src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,11 @@ impl IssuanceKey {
/// Constructs an Orchard issuance key from uniformly-random bytes.
///
/// Returns `None` if the bytes do not correspond to a valid Orchard issuance key.
pub fn from_bytes(sk_iss: [u8; 32]) -> CtOption<Self> {
let sk_iss = IssuanceKey(sk_iss);
pub fn from_bytes(imk: [u8; 32]) -> CtOption<Self> {
let imk = IssuanceKey(imk);
// If isk = 0 (A scalar value), discard this key.
let isk = IssuanceAuthorizingKey::derive_inner(&sk_iss);
CtOption::new(sk_iss, !isk.is_zero())
let isk = IssuanceAuthorizingKey::derive_inner(&imk);
CtOption::new(imk, !isk.is_zero())
}

/// Returns the raw bytes of the issuance key.
Expand Down Expand Up @@ -295,9 +295,9 @@ impl IssuanceKey {
pub struct IssuanceAuthorizingKey(redpallas::SigningKey<IssuanceAuth>);

impl IssuanceAuthorizingKey {
/// Derives isk from sk_iss. Internal use only, does not enforce all constraints.
fn derive_inner(sk_iss: &IssuanceKey) -> pallas::Scalar {
to_scalar(PrfExpand::ZsaIsk.expand(&sk_iss.0))
/// Derives isk from imk. Internal use only, does not enforce all constraints.
fn derive_inner(imk: &IssuanceKey) -> pallas::Scalar {
to_scalar(PrfExpand::ZsaIsk.expand(&imk.0))
}

/// Sign the provided message using the `IssuanceAuthorizingKey`.
Expand All @@ -311,8 +311,8 @@ impl IssuanceAuthorizingKey {
}

impl From<&IssuanceKey> for IssuanceAuthorizingKey {
fn from(sk_iss: &IssuanceKey) -> Self {
let isk = IssuanceAuthorizingKey::derive_inner(sk_iss);
fn from(imk: &IssuanceKey) -> Self {
let isk = IssuanceAuthorizingKey::derive_inner(imk);
// IssuanceAuthorizingKey cannot be constructed such that this assertion would fail.
assert!(!bool::from(isk.is_zero()));
IssuanceAuthorizingKey(conditionally_negate(isk))
Expand Down Expand Up @@ -1267,9 +1267,9 @@ mod tests {
let ask: SpendAuthorizingKey = (&sk).into();
assert_eq!(<[u8; 32]>::from(&ask.0), tv.ask);

let sk_iss = IssuanceKey::from_bytes(tv.sk).unwrap();
let imk = IssuanceKey::from_bytes(tv.sk).unwrap();

let isk: IssuanceAuthorizingKey = (&sk_iss).into();
let isk: IssuanceAuthorizingKey = (&imk).into();
assert_eq!(<[u8; 32]>::from(&isk.0), tv.isk);

let ak: SpendValidatingKey = (&ask).into();
Expand Down
12 changes: 6 additions & 6 deletions src/note/asset_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ impl AssetBase {
///
/// This is only used in tests.
pub(crate) fn random(rng: &mut impl RngCore) -> Self {
let sk_iss = IssuanceKey::random(rng);
let isk = IssuanceAuthorizingKey::from(&sk_iss);
let imk = IssuanceKey::random(rng);
let isk = IssuanceAuthorizingKey::from(&imk);
let ik = IssuanceValidatingKey::from(&isk);
let asset_descr = "zsa_asset";
AssetBase::derive(&ik, asset_descr)
Expand Down Expand Up @@ -165,21 +165,21 @@ pub mod testing {
prop_compose! {
/// Generate an asset ID
pub fn arb_zsa_asset_id()(
sk_iss in arb_issuance_key(),
imk in arb_issuance_key(),
str in "[A-Za-z]{255}"
) -> AssetBase {
let isk = IssuanceAuthorizingKey::from(&sk_iss);
let isk = IssuanceAuthorizingKey::from(&imk);
AssetBase::derive(&IssuanceValidatingKey::from(&isk), &str)
}
}

prop_compose! {
/// Generate an asset ID using a specific description
pub fn zsa_asset_id(asset_desc: String)(
sk_iss in arb_issuance_key(),
imk in arb_issuance_key(),
) -> AssetBase {
assert!(super::is_asset_desc_of_valid_size(&asset_desc));
let isk = IssuanceAuthorizingKey::from(&sk_iss);
let isk = IssuanceAuthorizingKey::from(&imk);
AssetBase::derive(&IssuanceValidatingKey::from(&isk), &asset_desc)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/supply_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ mod tests {
fn create_test_asset(asset_desc: &str) -> AssetBase {
use crate::keys::{IssuanceAuthorizingKey, IssuanceKey, IssuanceValidatingKey};

let sk_iss = IssuanceKey::from_bytes([0u8; 32]).unwrap();
let isk: IssuanceAuthorizingKey = (&sk_iss).into();
let imk = IssuanceKey::from_bytes([0u8; 32]).unwrap();
let isk: IssuanceAuthorizingKey = (&imk).into();

AssetBase::derive(&IssuanceValidatingKey::from(&isk), asset_desc)
}
Expand Down
4 changes: 2 additions & 2 deletions tests/zsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ fn prepare_keys() -> Keychain {
let fvk = FullViewingKey::from(&sk);
let recipient = fvk.address_at(0u32, Scope::External);

let sk_iss = IssuanceKey::from_bytes([0; 32]).unwrap();
let isk = IssuanceAuthorizingKey::from(&sk_iss);
let imk = IssuanceKey::from_bytes([0; 32]).unwrap();
let isk = IssuanceAuthorizingKey::from(&imk);
let ik = IssuanceValidatingKey::from(&isk);
Keychain {
pk,
Expand Down

0 comments on commit 64d4ed1

Please sign in to comment.