diff --git a/.gitmodules b/.gitmodules index 6b49797f2..fb2281edf 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,15 +1,6 @@ -[submodule "AFNetworking"] - path = AFNetworking - url = git://github.com/AFNetworking/AFNetworking.git [submodule "ZBar"] path = ZBar url = git://github.com/ZBar/ZBar.git [submodule "QR-Code-Encoder-for-Objective-C"] path = QR-Code-Encoder-for-Objective-C url = git://github.com/myang-git/QR-Code-Encoder-for-Objective-C.git -[submodule "MBProgressHUD"] - path = MBProgressHUD - url = git://github.com/matej/MBProgressHUD.git -[submodule "SocketRocket"] - path = SocketRocket - url = git@github.com:square/SocketRocket.git diff --git a/ZincWallet.xcodeproj/project.pbxproj b/ZincWallet.xcodeproj/project.pbxproj index 20c704245..c5e9bef75 100644 --- a/ZincWallet.xcodeproj/project.pbxproj +++ b/ZincWallet.xcodeproj/project.pbxproj @@ -724,6 +724,7 @@ 759145B717EB7CE00040D496 /* info@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 759145B617EB7CE00040D496 /* info@2x.png */; }; 759145B917EB87BF0040D496 /* info-pressed@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 759145B817EB87BF0040D496 /* info-pressed@2x.png */; }; 75920F86174AB82100C1C03D /* NSMutableData+Bitcoin.m in Sources */ = {isa = PBXBuildFile; fileRef = 75920F85174AB82100C1C03D /* NSMutableData+Bitcoin.m */; }; + 759292F8190046FB00CDA950 /* flash@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 759292F7190046FB00CDA950 /* flash@2x.png */; }; 7593BD0A17A24D1500F814F6 /* cameraguide-small@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 7593BD0917A24D1500F814F6 /* cameraguide-small@2x.png */; }; 7597028117E15B1E00CDC14A /* ZNNavigationBar.m in Sources */ = {isa = PBXBuildFile; fileRef = 7597028017E15B1E00CDC14A /* ZNNavigationBar.m */; }; 7597028417E15B5600CDC14A /* ZNStoryboardSegue.m in Sources */ = {isa = PBXBuildFile; fileRef = 7597028317E15B5600CDC14A /* ZNStoryboardSegue.m */; }; @@ -1778,6 +1779,7 @@ 759145B817EB87BF0040D496 /* info-pressed@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "info-pressed@2x.png"; sourceTree = ""; }; 75920F84174AB82100C1C03D /* NSMutableData+Bitcoin.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSMutableData+Bitcoin.h"; sourceTree = ""; }; 75920F85174AB82100C1C03D /* NSMutableData+Bitcoin.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSMutableData+Bitcoin.m"; sourceTree = ""; }; + 759292F7190046FB00CDA950 /* flash@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "flash@2x.png"; sourceTree = ""; }; 7593BD0917A24D1500F814F6 /* cameraguide-small@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "cameraguide-small@2x.png"; sourceTree = ""; }; 7597027F17E15B1E00CDC14A /* ZNNavigationBar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ZNNavigationBar.h; sourceTree = ""; }; 7597028017E15B1E00CDC14A /* ZNNavigationBar.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ZNNavigationBar.m; sourceTree = ""; }; @@ -3317,6 +3319,7 @@ 751E809E1789797500E3CFB2 /* refresh@2x.png */, 759145B617EB7CE00040D496 /* info@2x.png */, 759145B817EB87BF0040D496 /* info-pressed@2x.png */, + 759292F7190046FB00CDA950 /* flash@2x.png */, 75C2F3D3178D3061009F8CD3 /* cameraguide@2x.png */, 75C2F3D1178D3061009F8CD3 /* cameraguide-green@2x.png */, 75C2F3D2178D3061009F8CD3 /* cameraguide-red@2x.png */, @@ -3811,6 +3814,7 @@ 75D8F38C173ABE3C0080D95E /* InfoPlist.strings in Resources */, 75D8F394173ABE3C0080D95E /* Default.png in Resources */, 75D8F396173ABE3C0080D95E /* Default@2x.png in Resources */, + 759292F8190046FB00CDA950 /* flash@2x.png in Resources */, 75D8F398173ABE3C0080D95E /* Default-568h@2x.png in Resources */, 75D8F39B173ABE3C0080D95E /* MainStoryboard_iPhone.storyboard in Resources */, 75F17C4417455F2D00D9F228 /* deletetoleft-inv.png in Resources */, diff --git a/ZincWallet/NSString+Base58.h b/ZincWallet/NSString+Base58.h index 6720385a3..f67d4e26b 100644 --- a/ZincWallet/NSString+Base58.h +++ b/ZincWallet/NSString+Base58.h @@ -32,11 +32,12 @@ #define BITCOIN_PRIVKEY 128 #define BITCOIN_PRIVKEY_TEST 239 -#define BIP38_NOEC_PREFIX 0x0142 -#define BIP38_EC_PREFIX 0x0143 -#define BIP38_NOEC_FLAG (0x80 | 0x40) -#define BIP38_LOTSEQUENCE_FLAG 0x04 -#define BIP38_INVALID_FLAG (0x10 | 0x08 | 0x02 | 0x01) +#define BIP38_NOEC_PREFIX 0x0142 +#define BIP38_EC_PREFIX 0x0143 +#define BIP38_NOEC_FLAG (0x80 | 0x40) +#define BIP38_COMPRESSED_FLAG 0x20 +#define BIP38_LOTSEQUENCE_FLAG 0x04 +#define BIP38_INVALID_FLAG (0x10 | 0x08 | 0x02 | 0x01) CFAllocatorRef SecureAllocator(); diff --git a/ZincWallet/NSString+Base58.m b/ZincWallet/NSString+Base58.m index 30802c86a..80ca44641 100644 --- a/ZincWallet/NSString+Base58.m +++ b/ZincWallet/NSString+Base58.m @@ -101,6 +101,7 @@ + (NSString *)base58WithData:(NSData *)d BN_CTX *ctx = BN_CTX_new(); BIGNUM base, x, r; + BN_CTX_start(ctx); BN_init(&base); BN_init(&x); BN_init(&r); @@ -120,6 +121,7 @@ + (NSString *)base58WithData:(NSData *)d BN_clear_free(&r); BN_clear_free(&x); BN_free(&base); + BN_CTX_end(ctx); BN_CTX_free(ctx); NSString *ret = CFBridgingRelease(CFStringCreateWithCString(SecureAllocator(), &s[i], kCFStringEncodingUTF8)); @@ -143,7 +145,8 @@ - (NSData *)base58ToData unsigned int b; BN_CTX *ctx = BN_CTX_new(); BIGNUM base, x, y; - + + BN_CTX_start(ctx); BN_init(&base); BN_init(&x); BN_init(&y); @@ -198,6 +201,7 @@ - (NSData *)base58ToData BN_clear_free(&y); BN_clear_free(&x); BN_free(&base); + BN_CTX_end(ctx); BN_CTX_free(ctx); return d; diff --git a/ZincWallet/ZNElectrumSequence.m b/ZincWallet/ZNElectrumSequence.m index 660d581c2..0c409d4d0 100644 --- a/ZincWallet/ZNElectrumSequence.m +++ b/ZincWallet/ZNElectrumSequence.m @@ -143,7 +143,7 @@ - (NSArray *)privateKeys:(NSArray *)n internal:(BOOL)internal fromSeed:(NSData * NSData *_mpk = [[ZNKey keyWithSecret:secexp compressed:NO] publicKey]; NSData *mpk = [NSData dataWithBytesNoCopy:(unsigned char *)_mpk.bytes + 1 length:_mpk.length - 1 freeWhenDone:NO]; BN_CTX *ctx = BN_CTX_new(); - __block BIGNUM sequencebn, secexpbn, order; + BIGNUM sequencebn, secexpbn, order; EC_GROUP *group = EC_GROUP_new_by_curve_name(NID_secp256k1); BN_CTX_start(ctx); diff --git a/ZincWallet/ZNKey+BIP38.m b/ZincWallet/ZNKey+BIP38.m index 3a298c28e..30840e16c 100644 --- a/ZincWallet/ZNKey+BIP38.m +++ b/ZincWallet/ZNKey+BIP38.m @@ -27,13 +27,10 @@ #import "NSString+Base58.h" #import "NSData+Hash.h" #import "NSMutableData+Bitcoin.h" -#import -#import -#import +#import #import #import -#define BIP38_COMPRESSED_FLAG 0x20 #define BIP38_SCRYPT_N 16384 #define BIP38_SCRYPT_R 8 #define BIP38_SCRYPT_P 8 @@ -157,17 +154,17 @@ static void getPassfactor(BIGNUM *passfactor, uint8_t flag, uint64_t entropy, NS else BN_bin2bn(prefactor.bytes, (int)prefactor.length, passfactor); // passfactor = prefactor } -static NSData *getPasspoint(const BIGNUM *passfactor, BN_CTX *ctx) +static NSData *factorPoint(const BIGNUM *factor, BN_CTX *ctx) { - NSMutableData *passpoint = [NSMutableData secureDataWithLength:33]; + NSMutableData *point = [NSMutableData secureDataWithLength:33]; EC_GROUP *group = EC_GROUP_new_by_curve_name(NID_secp256k1); EC_POINT *p = EC_POINT_new(group); - EC_POINT_mul(group, p, passfactor, NULL, NULL, ctx); // passpoint = elliptic curve point G*passfactor - EC_POINT_point2oct(group, p, POINT_CONVERSION_COMPRESSED, passpoint.mutableBytes, passpoint.length, ctx); + EC_POINT_mul(group, p, factor, NULL, NULL, ctx); // point = elliptic curve point G*factor + EC_POINT_point2oct(group, p, POINT_CONVERSION_COMPRESSED, point.mutableBytes, point.length, ctx); EC_POINT_clear_free(p); EC_GROUP_free(group); - return passpoint; + return point; } static NSData *getDerived(NSData *passpoint, uint32_t addresshash, uint64_t entropy) @@ -204,7 +201,7 @@ + (NSString *)BIP38IntermediateCodeWithSalt:(uint64_t)salt andPassphrase:(NSStri [code appendBytes:"\x2C\xE9\xB3\xE1\xFF\x39\xE2\x53" length:8]; [code appendBytes:&salt length:sizeof(salt)]; - [code appendData:getPasspoint(&passfactor, ctx)]; + [code appendData:factorPoint(&passfactor, ctx)]; // passpoint = G*passfactor BN_clear_free(&passfactor); BN_CTX_end(ctx); @@ -235,7 +232,7 @@ + (NSString *)BIP38IntermediateCodeWithLot:(uint32_t)lot sequence:(uint16_t)sequ [code appendBytes:"\x2C\xE9\xB3\xE1\xFF\x39\xE2\x51" length:8]; [code appendData:entropy]; - [code appendData:getPasspoint(&passfactor, ctx)]; + [code appendData:factorPoint(&passfactor, ctx)]; // passpoint = G*passfactor BN_clear_free(&passfactor); BN_CTX_end(ctx); @@ -270,6 +267,8 @@ + (NSString *)BIP38KeyWithIntermediateCode:(NSString *)code seedb:(NSData *)seed pubKey.length = EC_POINT_point2oct(group, pubKeyPoint, form, NULL, 0, ctx); EC_POINT_point2oct(group, pubKeyPoint, form, pubKey.mutableBytes, pubKey.length, ctx); EC_POINT_clear_free(pubKeyPoint); + EC_POINT_clear_free(p); + EC_GROUP_free(group); uint16_t prefix = CFSwapInt16HostToBig(BIP38_EC_PREFIX); uint8_t flag = compressed ? BIP38_COMPRESSED_FLAG : 0; @@ -305,11 +304,8 @@ + (NSString *)BIP38KeyWithIntermediateCode:(NSString *)code seedb:(NSData *)seed [key appendData:encrypted2]; if (confcode) { - NSMutableData *pointb = [NSMutableData secureDataWithLength:33], *pointbx1, *pointbx2, *c; - - EC_POINT_mul(group, p, &factorb, NULL, NULL, ctx); // pointb = elliptic curve point G*factorb - EC_POINT_point2oct(group, p, POINT_CONVERSION_COMPRESSED, pointb.mutableBytes, pointb.length, ctx); - + NSData *pointb = factorPoint(&factorb, ctx); // pointb = G*factorb + NSMutableData *pointbx1, *pointbx2, *c; uint8_t pointbprefix = ((const uint8_t *)pointb.bytes)[0] ^ (((const uint8_t *)derived2)[31] & 0x01); // pointbx1 = AES256Encrypt(pointb[1...16] xor derived1[0...15], derived2) @@ -337,8 +333,6 @@ + (NSString *)BIP38KeyWithIntermediateCode:(NSString *)code seedb:(NSData *)seed *confcode = [NSString base58checkWithData:c]; } - EC_POINT_clear_free(p); - EC_GROUP_free(group); BN_clear_free(&factorb); BN_CTX_end(ctx); BN_CTX_free(ctx); @@ -368,7 +362,7 @@ + (BOOL)confirmWithBIP38ConfirmationCode:(NSString *)code address:(NSString *)ad BN_init(&passfactor); getPassfactor(&passfactor, flag, entropy, passphrase); - NSData *passpoint = getPasspoint(&passfactor, ctx); + NSData *passpoint = factorPoint(&passfactor, ctx); // passpoint = G*passfactor NSData *derived = getDerived(passpoint, addresshash, entropy); const uint64_t *derived1 = (const uint64_t *)derived.bytes, *derived2 = &derived1[4]; NSMutableData *pointb = [NSMutableData secureDataWithLength:33], *pubKey = [NSMutableData secureData]; @@ -401,9 +395,7 @@ + (BOOL)confirmWithBIP38ConfirmationCode:(NSString *)code address:(NSString *)ad BN_CTX_end(ctx); BN_CTX_free(ctx); - if (! [[[ZNKey keyWithPublicKey:pubKey] address] isEqual:address]) return NO; - - return YES; + return ([[[ZNKey keyWithPublicKey:pubKey] address] isEqual:address]) ? YES : NO; } - (instancetype)initWithBIP38Key:(NSString *)key andPassphrase:(NSString *)passphrase @@ -447,7 +439,7 @@ - (instancetype)initWithBIP38Key:(NSString *)key andPassphrase:(NSString *)passp BN_init(&passfactor); getPassfactor(&passfactor, flag, entropy, passphrase); - NSData *passpoint = getPasspoint(&passfactor, ctx); + NSData *passpoint = factorPoint(&passfactor, ctx); // passpoint = G*passfactor NSData *derived = getDerived(passpoint, addresshash, entropy); const uint64_t *derived1 = (const uint64_t *)derived.bytes, *derived2 = &derived1[4]; NSMutableData *seedb = [NSMutableData secureDataWithLength:24], *o = [NSMutableData secureDataWithLength:16]; diff --git a/ZincWallet/ZNMerkleBlock.m b/ZincWallet/ZNMerkleBlock.m index 56e506598..1279baadc 100644 --- a/ZincWallet/ZNMerkleBlock.m +++ b/ZincWallet/ZNMerkleBlock.m @@ -158,10 +158,10 @@ - (instancetype)initWithBlockHash:(NSData *)blockHash version:(uint32_t)version // true if merkle tree and timestamp are valid, and proof-of-work matches the stated difficulty target // NOTE: this only checks if the block difficulty matches the difficulty target in the header, it does not check if the -// target is correct for the block's height in the chain, use verifyDifficultyAtHeight: for that +// target is correct for the block's height in the chain, use verifyDifficultyFromPreviousBlock: for that - (BOOL)isValid { - __block NSMutableData *d = [NSMutableData data]; + NSMutableData *d = [NSMutableData data]; BIGNUM target, maxTarget, hash; int hashIdx = 0, flagIdx = 0; NSData *merkleRoot = diff --git a/ZincWallet/ZNPayViewController.m b/ZincWallet/ZNPayViewController.m index 35153f363..26f436055 100644 --- a/ZincWallet/ZNPayViewController.m +++ b/ZincWallet/ZNPayViewController.m @@ -36,6 +36,7 @@ #import "ZNBubbleView.h" #import "NSString+Base58.h" #import +#import //#define BT_CONNECT_TIMEOUT 5.0 #define BUTTON_HEIGHT 44.0 @@ -115,7 +116,7 @@ - (void)viewDidLoad } // else if ([url.scheme isEqual:@"zinc"] && [url.host isEqual:@"x-callback-url"]) { // if ([url.path isEqual:@"/tx"]) { -// __block NSString *status = nil; +// NSString *status = nil; // // for (NSString *arg in [url.query componentsSeparatedByString:@"&"]) { // NSArray *pair = [arg componentsSeparatedByString:@"="]; @@ -465,7 +466,7 @@ - (void)confirmSweep:(NSString *)privKey [self reset:nil]; } else if (tx) { - __block uint64_t fee = tx.standardFee, amount = fee; + uint64_t fee = tx.standardFee, amount = fee; for (NSNumber *amt in tx.outputAmounts) { amount += amt.unsignedLongLongValue; @@ -550,16 +551,19 @@ - (IBAction)doIt:(id)sender NSUInteger idx = [self.requestButtons indexOfObject:sender]; if ([self.requestIDs indexOfObject:QR_ID] == idx) { - //TODO: XXXX add an option to disable flash [self.navigationController presentViewController:self.zbarController animated:YES completion:^{ NSLog(@"present qr reader complete"); }]; - - // hide zbarController.view info button + + BOOL hasFlash = [[AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo] hasTorch]; + UIBarButtonItem *flashButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"flash.png"] + style:UIBarButtonItemStylePlain target:self action:@selector(flash:)]; + + // replace zbarController.view info button with flash toggle for (UIView *v in self.zbarController.view.subviews) { for (id t in v.subviews) { - if ([t isKindOfClass:[UIToolbar class]] && [[t items] count] > 0) { - [t setItems:@[[t items][0]]]; + if ([t isKindOfClass:[UIToolbar class]] && [[t items] count] > 1) { + [t setItems:hasFlash ? @[[t items][0], [t items][1], flashButton] : @[[t items][0], [t items][1]]]; } } } @@ -601,6 +605,13 @@ - (IBAction)cancel:(id)sender if (self.navigationController.topViewController == self.parentViewController) [self reset:sender]; } +- (IBAction)flash:(id)sender +{ + AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; + + device.torchMode = device.torchActive ? AVCaptureTorchModeOff : AVCaptureTorchModeOn; +} + #pragma mark - ZNAmountViewControllerDelegate - (void)amountViewController:(ZNAmountViewController *)amountViewController selectedAmount:(uint64_t)amount diff --git a/ZincWallet/ZNSettingsViewController.m b/ZincWallet/ZNSettingsViewController.m index ed2ac33d0..ec3952a1a 100644 --- a/ZincWallet/ZNSettingsViewController.m +++ b/ZincWallet/ZNSettingsViewController.m @@ -156,7 +156,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N static NSString *disclosureIdent = @"ZNDisclosureCell", *transactionIdent = @"ZNTransactionCell", *actionIdent = @"ZNActionCell", *restoreIdent = @"ZNRestoreCell"; UITableViewCell *cell = nil; - __block UILabel *textLabel, *detailTextLabel, *unconfirmedLabel, *sentLabel, *noTxLabel, *localCurrencyLabel; + UILabel *textLabel, *detailTextLabel, *unconfirmedLabel, *sentLabel, *noTxLabel, *localCurrencyLabel; switch (indexPath.section) { case 0: diff --git a/ZincWallet/ZNTransactionEntity.m b/ZincWallet/ZNTransactionEntity.m index a6292feaa..44f1895dd 100644 --- a/ZincWallet/ZNTransactionEntity.m +++ b/ZincWallet/ZNTransactionEntity.m @@ -86,7 +86,7 @@ - (instancetype)setAttributesFromTx:(ZNTransaction *)tx - (ZNTransaction *)transaction { - __block ZNTransaction *tx = [ZNTransaction new]; + ZNTransaction *tx = [ZNTransaction new]; [[self managedObjectContext] performBlockAndWait:^{ tx.txHash = self.txHash; diff --git a/ZincWallet/ZNWallet.m b/ZincWallet/ZNWallet.m index ddde56652..409abcd7e 100644 --- a/ZincWallet/ZNWallet.m +++ b/ZincWallet/ZNWallet.m @@ -281,7 +281,7 @@ - (BOOL)containsAddress:(NSString *)address // returns an unsigned transaction that sends the specified amount from the wallet to the given address - (ZNTransaction *)transactionFor:(uint64_t)amount to:(NSString *)address withFee:(BOOL)fee { - __block uint64_t balance = 0, standardFee = 0; + uint64_t balance = 0, standardFee = 0; ZNTransaction *transaction = [ZNTransaction new]; [transaction addOutputAddress:address amount:amount]; diff --git a/ZincWallet/flash@2x.png b/ZincWallet/flash@2x.png new file mode 100644 index 000000000..851c96ca9 Binary files /dev/null and b/ZincWallet/flash@2x.png differ diff --git a/ZincWalletTests/ZincWalletTests.m b/ZincWalletTests/ZincWalletTests.m index 654b705f8..165ff83b7 100644 --- a/ZincWalletTests/ZincWalletTests.m +++ b/ZincWalletTests/ZincWalletTests.m @@ -229,7 +229,7 @@ - (void)testKeyWithBIP38Key // password NFC unicode normalization test key = [ZNKey keyWithBIP38Key:@"6PRW5o9FLp4gJDDVqJQKJFTpMvdsSGJxMYHtHaQBF3ooa8mwD69bapcDQn" - andPassphrase:@"\u03D2\u0301\x00\U00010400\U0001F4A9"]; + andPassphrase:@"\u03D2\u0301\0\U00010400\U0001F4A9"]; NSLog(@"privKey = %@", key.privateKey); XCTAssertEqualObjects(@"5Jajm8eQ22H3pGWLEVCXyvND8dQZhiQhoLJNKjYXk9roUFTMSZ4", key.privateKey, @"[ZNKey keyWithBIP38Key:andPassphrase:]");