Skip to content

Commit c3aa980

Browse files
committed
Added checks if scanned / typed in address is actually the correct type (private / public)
1 parent e7cc563 commit c3aa980

8 files changed

Lines changed: 67 additions & 19 deletions

File tree

BitStore.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
9A8D3C49195E247800E88A1C /* ShopsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A8D3C48195E247800E88A1C /* ShopsViewController.m */; };
8888
9A8D3C50195E248C00E88A1C /* ChangeCurrencyViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A8D3C4E195E248C00E88A1C /* ChangeCurrencyViewController.m */; };
8989
9A8D3C53195E258600E88A1C /* SettingsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A8D3C52195E258600E88A1C /* SettingsViewController.m */; };
90+
9A91EF7D19D1D1B00011D982 /* BTCAddress+BitStore.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A91EF7C19D1D1B00011D982 /* BTCAddress+BitStore.m */; };
9091
9A97A0BD19D058530023C9AD /* piwiktracker.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 9A97A0BB19D058530023C9AD /* piwiktracker.xcdatamodeld */; };
9192
9A97A0C319D05BBF0023C9AD /* libicucore.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 9A97A0C219D05BBF0023C9AD /* libicucore.dylib */; };
9293
9A97A0C519D05C820023C9AD /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9A97A0C419D05C820023C9AD /* CFNetwork.framework */; };
@@ -279,6 +280,8 @@
279280
9A8D3C4E195E248C00E88A1C /* ChangeCurrencyViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ChangeCurrencyViewController.m; sourceTree = "<group>"; };
280281
9A8D3C51195E258600E88A1C /* SettingsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SettingsViewController.h; sourceTree = "<group>"; };
281282
9A8D3C52195E258600E88A1C /* SettingsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SettingsViewController.m; sourceTree = "<group>"; };
283+
9A91EF7B19D1D1B00011D982 /* BTCAddress+BitStore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "BTCAddress+BitStore.h"; sourceTree = "<group>"; };
284+
9A91EF7C19D1D1B00011D982 /* BTCAddress+BitStore.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "BTCAddress+BitStore.m"; sourceTree = "<group>"; };
282285
9A97A0BC19D058530023C9AD /* piwiktracker.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = piwiktracker.xcdatamodel; sourceTree = "<group>"; };
283286
9A97A0C219D05BBF0023C9AD /* libicucore.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libicucore.dylib; path = usr/lib/libicucore.dylib; sourceTree = SDKROOT; };
284287
9A97A0C419D05C820023C9AD /* CFNetwork.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CFNetwork.framework; path = System/Library/Frameworks/CFNetwork.framework; sourceTree = SDKROOT; };
@@ -438,6 +441,8 @@
438441
9A265ED71965EE03005BE50A /* Utils */ = {
439442
isa = PBXGroup;
440443
children = (
444+
9A91EF7B19D1D1B00011D982 /* BTCAddress+BitStore.h */,
445+
9A91EF7C19D1D1B00011D982 /* BTCAddress+BitStore.m */,
441446
9AA466BA1972D82A00A7B562 /* Color.h */,
442447
9AA466BB1972D82A00A7B562 /* Color.m */,
443448
9AF0C4F5196B3A0200F62DB5 /* iOSFix.h */,
@@ -968,6 +973,7 @@
968973
9A67A75C1950D70A001FCE32 /* AddContactViewController.m in Sources */,
969974
9A70263B195F2F960033026C /* SwipeViewController.m in Sources */,
970975
9A073F3F1996EDCD007E0D0F /* Order.m in Sources */,
976+
9A91EF7D19D1D1B00011D982 /* BTCAddress+BitStore.m in Sources */,
971977
9A67A7841950D70A001FCE32 /* Receiver.m in Sources */,
972978
9A702653196098BF0033026C /* MessageHelper.m in Sources */,
973979
9A65236F196F630C00AD5EFB /* AddressHelper.m in Sources */,

BitStore/BitStore-Prefix.pch

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#import "Environment.h"
2424
#import "Settings.h"
2525
#import "Keys.h"
26+
#import "BTCAddress+BitStore.h"
2627

2728
#define l10n(key) NSLocalizedString(key, nil)
2829

BitStore/Controller/Account/Send/SendViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ - (void)updateFields {
191191
}
192192

193193
BTCAddress* addr = [BTCAddress addressWithBase58String:[self address]];
194-
if (!error && addr != nil && _satoshi > 0) {
194+
if (!error && addr != nil && [addr isPublicAddress] && _satoshi > 0) {
195195
self.navigationItem.rightBarButtonItem.enabled = YES;
196196
} else {
197197
self.navigationItem.rightBarButtonItem.enabled = NO;

BitStore/Controller/Contact/AddContactViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRang
9999
}
100100

101101
BTCAddress* addr = [BTCAddress addressWithBase58String:_addressField.text];
102-
if (addr != nil && _nameField.text.length > 0 && !exists) {
102+
if (addr != nil && [addr isPublicAddress] && _nameField.text.length > 0 && !exists) {
103103
self.navigationItem.rightBarButtonItem.enabled = YES;
104104
} else {
105105
self.navigationItem.rightBarButtonItem.enabled = NO;

BitStore/Controller/Settings/KeysViewController.m

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,18 @@ - (void)add:(id)sender {
6565

6666
- (void)scannedAddress:(NSString *)address amount:(NSString *)amount {
6767
[_scanViewController dismissViewControllerAnimated:YES completion:nil];
68-
BTCKey* k = [[BTCKey alloc] initWithPrivateKeyAddress:[BTCPrivateKeyAddress addressWithBase58String:address]];
69-
if (k != nil) {
70-
[Lockbox setArray:[[Lockbox arrayForKey:@"bitstore_3"] arrayByAddingObject:k.privateKeyAddress.base58String] forKey:@"bitstore_3"];
71-
Address* addr = [[Address alloc] init];
72-
addr.address = k.uncompressedPublicKeyAddress.base58String;
73-
[addr refresh];
74-
[[AddressHelper instance] addAddress:addr];
75-
[self updateValues];
68+
BTCAddress* btcaddr = [BTCAddress addressWithBase58String:address];
69+
BTCKey* k;
70+
if ([btcaddr isPrivateAddress]) {
71+
k = [[BTCKey alloc] initWithPrivateKeyAddress:(BTCPrivateKeyAddress *)btcaddr];
72+
if (k != nil) {
73+
[Lockbox setArray:[[Lockbox arrayForKey:@"bitstore_3"] arrayByAddingObject:k.privateKeyAddress.base58String] forKey:@"bitstore_3"];
74+
Address* addr = [[Address alloc] init];
75+
addr.address = k.uncompressedPublicKeyAddress.base58String;
76+
[addr refresh];
77+
[[AddressHelper instance] addAddress:addr];
78+
[self updateValues];
79+
}
7680
}
7781
}
7882

BitStore/Controller/Settings/SwipeViewController.m

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,15 @@ - (void)scannedAddress:(NSString *)address amount:(NSString *)amount {
6464
BTCPrivateKeyAddress* addr = [BTCPrivateKeyAddress addressWithBase58String:address];
6565
[self stopScan];
6666

67-
if (addr == nil) {
67+
if (addr != nil && [addr isPrivateAddress]) {
68+
BTCKey* key = [[BTCKey alloc] initWithPrivateKeyAddress:addr];
69+
70+
_loadingAlert = [[UIAlertView alloc] init];
71+
_loadingAlert.title = l10n(@"please_wait");
72+
[_loadingAlert show];
73+
74+
[self performSelector:@selector(checkBalance:) withObject:key afterDelay:0.01];
75+
} else {
6876
UIBAlertView* av = [[UIBAlertView alloc] initWithTitle:l10n(@"error") message:l10n(@"not_a_key") cancelButtonTitle:l10n(@"cancel") otherButtonTitles:l10n(@"retry"), nil];
6977
[av showWithDismissHandler:^(NSInteger selectedIndex, NSString *selectedTitle, BOOL didCancel) {
7078
if (didCancel) {
@@ -73,14 +81,6 @@ - (void)scannedAddress:(NSString *)address amount:(NSString *)amount {
7381
[self startScan];
7482
}
7583
}];
76-
} else {
77-
BTCKey* key = [[BTCKey alloc] initWithPrivateKeyAddress:addr];
78-
79-
_loadingAlert = [[UIAlertView alloc] init];
80-
_loadingAlert.title = l10n(@"please_wait");
81-
[_loadingAlert show];
82-
83-
[self performSelector:@selector(checkBalance:) withObject:key afterDelay:0.01];
8484
}
8585
}
8686

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// BTCAddress+BitStore.h
3+
// BitStore
4+
//
5+
// Created by Dylan Marriott on 23.09.14.
6+
// Copyright (c) 2014 Dylan Marriott. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
@interface BTCAddress (BitStore)
12+
13+
- (BOOL)isPrivateAddress;
14+
- (BOOL)isPublicAddress;
15+
16+
@end
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// BTCAddress+BitStore.m
3+
// BitStore
4+
//
5+
// Created by Dylan Marriott on 23.09.14.
6+
// Copyright (c) 2014 Dylan Marriott. All rights reserved.
7+
//
8+
9+
#import "BTCAddress+BitStore.h"
10+
11+
@implementation BTCAddress (BitStore)
12+
13+
- (BOOL)isPrivateAddress {
14+
return [self isKindOfClass:[BTCPrivateKeyAddress class]];
15+
}
16+
17+
- (BOOL)isPublicAddress {
18+
return [self isKindOfClass:[BTCPublicKeyAddress class]];
19+
}
20+
21+
@end

0 commit comments

Comments
 (0)