Created
August 12, 2018 10:04
-
-
Save ricmoo/87f62f767c39e57283b70d72695d550e to your computer and use it in GitHub Desktop.
ENSHack EthersWallet Patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 27821ab4c5cb6cd1654b32d3cbed59ff98feec22 Mon Sep 17 00:00:00 2001 | |
From: Richard Moore <github@ricmoo.com> | |
Date: Sun, 12 Aug 2018 11:02:34 +0100 | |
Subject: [PATCH] do NOT use; only for the ENS Hackathon dmeo. | |
--- | |
.../src/Utilities/Signers/CloudKeychainSigner.m | 2 +- | |
EthersWallet/src/Utilities/Signers/FireflySigner.m | 75 +++++++++++++++++++--- | |
EthersWallet/src/Utilities/Signers/Signer.h | 2 +- | |
EthersWallet/src/Utilities/Signers/Signer.m | 2 +- | |
.../ScannerConfigController.m | 2 +- | |
.../TransactionConfigController.m | 2 +- | |
6 files changed, 72 insertions(+), 13 deletions(-) | |
diff --git a/EthersWallet/src/Utilities/Signers/CloudKeychainSigner.m b/EthersWallet/src/Utilities/Signers/CloudKeychainSigner.m | |
index 6a217c6..c581fff 100644 | |
--- a/EthersWallet/src/Utilities/Signers/CloudKeychainSigner.m | |
+++ b/EthersWallet/src/Utilities/Signers/CloudKeychainSigner.m | |
@@ -905,7 +905,7 @@ - (void)_send:(Transaction *)transaction callback:(void (^)(Transaction *, NSErr | |
}]; | |
} | |
-- (ConfigController*)send:(Transaction *)transaction callback:(void (^)(Transaction *, NSError *))callback { | |
+- (ConfigController*)send:(Transaction *)transaction nameHint: (NSString*)nameHint callback:(void (^)(Transaction *, NSError *))callback { | |
transaction = [transaction copy]; | |
NSLog(@"CloudKeychainSigner: Sending - address=%@ transaction=%@", _account.address, transaction); | |
diff --git a/EthersWallet/src/Utilities/Signers/FireflySigner.m b/EthersWallet/src/Utilities/Signers/FireflySigner.m | |
index b42b5ac..9d10d90 100644 | |
--- a/EthersWallet/src/Utilities/Signers/FireflySigner.m | |
+++ b/EthersWallet/src/Utilities/Signers/FireflySigner.m | |
@@ -150,19 +150,78 @@ - (void)bleCast:(BLECast *)bleCast didHopPayload:(NSData *)payload index:(uint8_ | |
#pragma mark - Sending | |
-- (ConfigController*)send:(Transaction *)transaction callback:(void (^)(Transaction *, NSError *))callback { | |
+NSData *padBytes32Left(NSData *data) { | |
+ if (data.length > 32) { return nil; } | |
+ SecureData *padded = [SecureData secureDataWithCapacity:32]; | |
+ for (int i = 0; i < 32 - data.length; i++) { | |
+ [padded appendByte:0]; | |
+ } | |
+ [padded appendData:data]; | |
+ return padded.data; | |
+} | |
+ | |
+NSData *padBytes32Right(NSData *data) { | |
+ if (data.length > 32) { return nil; } | |
+ SecureData *padded = [SecureData secureDataWithCapacity:32]; | |
+ [padded appendData:data]; | |
+ for (int i = 0; i < 32 - data.length; i++) { | |
+ [padded appendByte:0]; | |
+ } | |
+ return padded.data; | |
+} | |
+ | |
+- (ConfigController*)send:(Transaction *)transaction nameHint: (NSString*)nameHint callback:(void (^)(Transaction *, NSError *))callback { | |
transaction = [transaction copy]; | |
- NSLog(@"FireflySigner: Sending - address=%@ transaction=%@", self.address.checksumAddress, transaction); | |
- | |
+ Address *contractAddress = [Address addressWithString:@"0x199862247977a88aD825e8d4652a9d7a6EF0f40d"]; | |
+ | |
__weak FireflySigner *weakSelf = self; | |
+ | |
+ NSData *broadcastData = nil; | |
- NSData *unsignedTransaction = [transaction unsignedSerialize]; | |
- SecureData *data = [SecureData secureDataWithCapacity:unsignedTransaction.length + 1]; | |
- [data appendByte:0x00]; | |
- [data appendData:unsignedTransaction]; | |
+ if (nameHint && contractAddress) { | |
+ NSLog(@"FireflySigner: Sending Contract - address=%@ transaction=%@", contractAddress, transaction); | |
+ | |
+ // sendTransaction(bytes32 name, uint256 value, uint256 nonce) | |
+ | |
+ SecureData *data = [SecureData secureDataWithCapacity:4 + 3 * 32]; | |
+ [data appendData:[SecureData hexStringToData:@"0xc2ae1a53"]]; | |
+ [data appendData:padBytes32Right([nameHint dataUsingEncoding:NSUTF8StringEncoding])]; | |
+ [data appendData:padBytes32Left([transaction.value data])]; | |
+ [data appendData:padBytes32Left([[BigNumber bigNumberWithInteger:transaction.nonce] data])]; | |
+ | |
+ Transaction *proxyTransaction = [Transaction transaction]; | |
+ proxyTransaction.toAddress = contractAddress; | |
+ proxyTransaction.gasPrice = transaction.gasPrice; | |
+ proxyTransaction.gasLimit = [BigNumber bigNumberWithInteger:750000]; | |
+ proxyTransaction.nonce = transaction.nonce; | |
+ proxyTransaction.data = data.data; | |
+ proxyTransaction.chainId = transaction.chainId; | |
+ | |
+ transaction = proxyTransaction; | |
+ | |
+ NSData *unsignedTransaction = [transaction unsignedSerialize]; | |
+ SecureData *signData = [SecureData secureDataWithCapacity:unsignedTransaction.length + 1]; | |
+ [signData appendByte:0x04]; | |
+ [signData appendData:unsignedTransaction]; | |
+ | |
+ NSLog(@"Unsigned: %@", unsignedTransaction); | |
+ | |
+ broadcastData = signData.data; | |
+ | |
+ } else { | |
+ NSLog(@"FireflySigner: Sending - address=%@ transaction=%@", self.address.checksumAddress, transaction); | |
+ | |
+ NSData *unsignedTransaction = [transaction unsignedSerialize]; | |
+ SecureData *data = [SecureData secureDataWithCapacity:unsignedTransaction.length + 1]; | |
+ [data appendByte:0x00]; | |
+ [data appendData:unsignedTransaction]; | |
+ | |
+ broadcastData = data.data; | |
+ } | |
- BOOL broadcasting = [self broadcast:data.data]; | |
+ NSLog(@"Broadcast: %@", broadcastData); | |
+ BOOL broadcasting = [self broadcast:broadcastData]; | |
if (!broadcasting) { | |
dispatch_async(dispatch_get_main_queue(), ^() { | |
diff --git a/EthersWallet/src/Utilities/Signers/Signer.h b/EthersWallet/src/Utilities/Signers/Signer.h | |
index f155f9d..ac9bc46 100644 | |
--- a/EthersWallet/src/Utilities/Signers/Signer.h | |
+++ b/EthersWallet/src/Utilities/Signers/Signer.h | |
@@ -133,7 +133,7 @@ typedef enum SignerTextMessage { | |
// - Secret Storage JSON wallets support signing with unlocked signers | |
//@property (nonatomic, readonly) BOOL supportsSign; | |
-- (ConfigController*)send: (Transaction*)transaction callback: (void (^)(Transaction*, NSError*))callback; | |
+- (ConfigController*)send: (Transaction*)transaction nameHint: (NSString*)nameHint callback: (void (^)(Transaction*, NSError*))callback; | |
- (ConfigController*)signMessage: (NSData*)message callback: (void (^)(Signature*, NSError*))callback; | |
diff --git a/EthersWallet/src/Utilities/Signers/Signer.m b/EthersWallet/src/Utilities/Signers/Signer.m | |
index 7fb8f95..cbf56f9 100644 | |
--- a/EthersWallet/src/Utilities/Signers/Signer.m | |
+++ b/EthersWallet/src/Utilities/Signers/Signer.m | |
@@ -496,7 +496,7 @@ - (void)unlockPassword:(NSString *)password callback:(void (^)(Signer *, NSError | |
}); | |
} | |
-- (ConfigController*)send:(Transaction *)transaction callback:(void (^)(Transaction *, NSError *))callback { | |
+- (ConfigController*)send:(Transaction *)transaction nameHint: (NSString*)nameHint callback:(void (^)(Transaction *, NSError *))callback { | |
dispatch_async(dispatch_get_main_queue(), ^() { | |
callback(nil, [NSError errorWithDomain:SignerErrorDomain code:SignerErrorNotImplemented userInfo:@{}]); | |
}); | |
diff --git a/EthersWallet/src/ViewControllers/ConfigViewControllers/ScannerConfigController.m b/EthersWallet/src/ViewControllers/ConfigViewControllers/ScannerConfigController.m | |
index 40b957b..91a369a 100644 | |
--- a/EthersWallet/src/ViewControllers/ConfigViewControllers/ScannerConfigController.m | |
+++ b/EthersWallet/src/ViewControllers/ConfigViewControllers/ScannerConfigController.m | |
@@ -1181,7 +1181,7 @@ - (BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)rang | |
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText { | |
[self clearTextChangeTimer]; | |
- BOOL maybeValid = [searchText hasSuffix:@".eth"]; | |
+ BOOL maybeValid = [searchText hasSuffix:@".eth"] || [searchText hasSuffix:@".xyz"]; | |
/* | |
@TODO: Support .test on Ropsten? | |
if (_signer.provider.testnet && [searchText hasSuffix:@".test"]) { | |
diff --git a/EthersWallet/src/ViewControllers/ConfigViewControllers/TransactionConfigController.m b/EthersWallet/src/ViewControllers/ConfigViewControllers/TransactionConfigController.m | |
index ed060c2..6442247 100644 | |
--- a/EthersWallet/src/ViewControllers/ConfigViewControllers/TransactionConfigController.m | |
+++ b/EthersWallet/src/ViewControllers/ConfigViewControllers/TransactionConfigController.m | |
@@ -687,7 +687,7 @@ - (void)loadView { | |
weakSelf.sending = YES; | |
weakSelf.feeWarningTextView.text = @""; | |
[weakSelf updateButton]; | |
- ConfigController *config = [weakSelf.signer send:weakSelf.transaction callback:^(Transaction *transaction, NSError *error) { | |
+ ConfigController *config = [weakSelf.signer send:weakSelf.transaction nameHint:weakSelf.nameHint callback:^(Transaction *transaction, NSError *error) { | |
if (error) { | |
NSString *description = [error localizedDescription]; | |
if (weakSelf.action == WalletTransactionActionCancel) { | |
-- | |
2.15.2 (Apple Git-101.1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment