damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit 88306d00a3edfea2523210bb50c33bc7435b6da6
parent 616de2eebc191759ce0516f2d83555e355b680cf
Author: William Casarin <jb55@jb55.com>
Date:   Tue,  1 Aug 2023 17:57:01 -0700

key: generate a FullKeypair when generating new keys

Diffstat:
Mdamus/Models/CreateAccountModel.swift | 4++--
Mdamus/Nostr/NostrEvent.swift | 2+-
Mdamus/Util/Keys.swift | 4++--
Mdamus/Views/CreateAccountView.swift | 2+-
Mdamus/Views/Settings/KeySettingsView.swift | 2+-
MdamusTests/UserSearchCacheTests.swift | 2+-
MdamusTests/ZapTests.swift | 4++--
7 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/damus/Models/CreateAccountModel.swift b/damus/Models/CreateAccountModel.swift @@ -38,8 +38,8 @@ class CreateAccountModel: ObservableObject { init(real: String = "", nick: String = "", about: String = "") { let keypair = generate_new_keypair() self.pubkey = keypair.pubkey - self.privkey = keypair.privkey! - + self.privkey = keypair.privkey + self.real_name = real self.nick_name = nick self.about = about diff --git a/damus/Nostr/NostrEvent.swift b/damus/Nostr/NostrEvent.swift @@ -659,7 +659,7 @@ func make_zap_request_event(keypair: FullKeypair, content: String, relays: [Rela break case .anon: tags.append(["anon"]) - kp = generate_new_keypair().to_full()! + kp = generate_new_keypair() case .priv: guard let priv_kp = generate_private_keypair(our_privkey: keypair.privkey, id: target.id, created_at: now) else { return nil diff --git a/damus/Util/Keys.swift b/damus/Util/Keys.swift @@ -102,11 +102,11 @@ func bech32_note_id(_ evid: String) -> String? { return bech32_encode(hrp: "note", bytes) } -func generate_new_keypair() -> Keypair { +func generate_new_keypair() -> FullKeypair { let key = try! secp256k1.Signing.PrivateKey() let privkey = hex_encode(key.rawRepresentation) let pubkey = hex_encode(Data(key.publicKey.xonly.bytes)) - return Keypair(pubkey: pubkey, privkey: privkey) + return FullKeypair(pubkey: pubkey, privkey: privkey) } func privkey_to_pubkey_raw(sec: [UInt8]) -> Pubkey? { diff --git a/damus/Views/CreateAccountView.swift b/damus/Views/CreateAccountView.swift @@ -19,7 +19,7 @@ struct CreateAccountView: View { func regen_key() { let keypair = generate_new_keypair() self.account.pubkey = keypair.pubkey - self.account.privkey = keypair.privkey! + self.account.privkey = keypair.privkey } var body: some View { diff --git a/damus/Views/Settings/KeySettingsView.swift b/damus/Views/Settings/KeySettingsView.swift @@ -110,7 +110,7 @@ struct KeySettingsView: View { struct KeySettingsView_Previews: PreviewProvider { static var previews: some View { let kp = generate_new_keypair() - KeySettingsView(keypair: kp) + KeySettingsView(keypair: kp.to_keypair()) } } diff --git a/damusTests/UserSearchCacheTests.swift b/damusTests/UserSearchCacheTests.swift @@ -10,7 +10,7 @@ import XCTest final class UserSearchCacheTests: XCTestCase { - var keypair: Keypair? = nil + var keypair: FullKeypair? = nil let damusState = DamusState.empty let nip05 = "_@somedomain.com" diff --git a/damusTests/ZapTests.swift b/damusTests/ZapTests.swift @@ -20,8 +20,8 @@ final class ZapTests: XCTestCase { } func test_private_zap() throws { - let alice = generate_new_keypair().to_full()! - let bob = generate_new_keypair().to_full()! + let alice = generate_new_keypair() + let bob = generate_new_keypair() let target = ZapTarget.profile(bob.pubkey) let message = "hey bob!"