From 0a653e928b2c355aeba0e996804030507007def2 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Mon, 13 May 2019 12:00:13 +1000 Subject: [PATCH] Add share public key button --- .../AppSettings/AppSettingsViewController.m | 13 +++++++++++++ Signal/translations/en.lproj/Localizable.strings | 1 + .../src/Loki/Extensions/ECKeyPair.swift | 4 ++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Signal/src/ViewControllers/AppSettings/AppSettingsViewController.m b/Signal/src/ViewControllers/AppSettings/AppSettingsViewController.m index c0045cd5e..b1a9c6375 100644 --- a/Signal/src/ViewControllers/AppSettings/AppSettingsViewController.m +++ b/Signal/src/ViewControllers/AppSettings/AppSettingsViewController.m @@ -223,6 +223,12 @@ }]]; #endif + [section + addItem:[self destructiveButtonItemWithTitle:NSLocalizedString(@"Share Public Key", @"") + accessibilityIdentifier:ACCESSIBILITY_IDENTIFIER_WITH_NAME(self, @"share_public_key") + selector:@selector(sharePublicKey) + color:[UIColor ows_materialBlueColor]]]; + if (TSAccountManager.sharedInstance.isDeregistered) { [section addItem:[self destructiveButtonItemWithTitle:NSLocalizedString(@"SETTINGS_REREGISTER_BUTTON", @"Label for re-registration button.") @@ -471,6 +477,13 @@ } } +- (void)sharePublicKey +{ + NSString *publicKey = OWSIdentityManager.sharedManager.identityKeyPair.hexEncodedPublicKey; + UIActivityViewController *shareVC = [[UIActivityViewController alloc] initWithActivityItems:@[ publicKey ] applicationActivities:nil]; + [self presentViewController:shareVC animated:YES completion:nil]; +} + - (void)reregisterUser { [RegistrationUtils showReregistrationUIFromViewController:self]; diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index c1c50bf36..86451b27a 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -2570,3 +2570,4 @@ "No search results" = "No search results"; "Calculating proof of work" = "Calculating proof of work"; "Failed to calculate proof of work." = "Failed to calculate proof of work."; +"Share Public Key" = "Share Public Key"; diff --git a/SignalServiceKit/src/Loki/Extensions/ECKeyPair.swift b/SignalServiceKit/src/Loki/Extensions/ECKeyPair.swift index 7f088d866..cd0d4d88e 100644 --- a/SignalServiceKit/src/Loki/Extensions/ECKeyPair.swift +++ b/SignalServiceKit/src/Loki/Extensions/ECKeyPair.swift @@ -1,11 +1,11 @@ public extension ECKeyPair { - var hexEncodedPrivateKey: String { + @objc var hexEncodedPrivateKey: String { return privateKey.map { String(format: "%02hhx", $0) }.joined() } - var hexEncodedPublicKey: String { + @objc var hexEncodedPublicKey: String { // Prefixing with "05" is necessary for what seems to be a sort of Signal public key versioning system return "05" + publicKey.map { String(format: "%02hhx", $0) }.joined() }