commit 9f48fcb6401eb0d6879dc80252adbe04477a3275 parent fae626b6c7ff0934b45a13848cd854c037386bbd Author: William Casarin <jb55@jb55.com> Date: Mon, 26 Dec 2022 19:12:50 -0800 keypair: don't calculate bech32_{priv,pub}key each time Diffstat:
M | damus/Util/Keys.swift | | | 13 | +++++++------ |
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/damus/Util/Keys.swift b/damus/Util/Keys.swift @@ -15,13 +15,14 @@ let PRIVKEY_HRP = "nsec" struct Keypair { let pubkey: String let privkey: String? + let pubkey_bech32: String + let privkey_bech32: String? - var pubkey_bech32: String { - return bech32_pubkey(pubkey)! - } - - var privkey_bech32: String? { - return privkey.flatMap { bech32_privkey($0) } + init(pubkey: String, privkey: String?) { + self.pubkey = pubkey + self.privkey = privkey + self.pubkey_bech32 = bech32_pubkey(pubkey) ?? pubkey + self.privkey_bech32 = privkey.flatMap { bech32_privkey($0) } } }