From ea21daf564d636f5ff4419216728adbc050c985d Mon Sep 17 00:00:00 2001 From: moana Date: Wed, 18 Sep 2024 15:36:34 +0200 Subject: [PATCH] core: Avoid code duplication in `sk.owns` by calling `gen_note_sk` Resolves #246 --- core/CHANGELOG.md | 4 ++++ core/src/keys/secret.rs | 6 ++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index dfc0008..58b07e8 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Call `gen_note_sk` in `SecretKey::owns` to avoid code duplication [#246] + ## [0.32.0] - 2024-08-14 ### Changed diff --git a/core/src/keys/secret.rs b/core/src/keys/secret.rs index 83d97e2..82049f0 100644 --- a/core/src/keys/secret.rs +++ b/core/src/keys/secret.rs @@ -89,11 +89,9 @@ impl SecretKey { /// Checks if `note_pk ?= (H(R · a) + b) · G` pub fn owns(&self, stealth_address: &StealthAddress) -> bool { - let aR = stealth_address.R() * self.a(); - let hash_aR = hash(&aR); - let note_sk = hash_aR + self.b(); + let note_sk = self.gen_note_sk(stealth_address); - let note_pk = GENERATOR_EXTENDED * note_sk; + let note_pk = GENERATOR_EXTENDED * note_sk.as_ref(); stealth_address.note_pk().as_ref() == ¬e_pk }