45 |
46 |
47 |
AirbitzCore (ABC) is an iOS and Mac OSX client-side blockchain and Edge Security SDK providing auto-encrypted and auto-backed up accounts and wallets with zero-knowledge security and privacy. All blockchain/bitcoin private and public keys are fully encrypted by the users' credentials before being backed up on to peer to peer servers. ABC allows developers to create new Airbitz wallet accounts or login to pre-existing accounts. Account encrypted data is automatically synchronized between all devices and apps using the Airbitz SDK. This allows a third party application to generate payment requests or send funds for the users' account that may have been created on the Airbitz Mobile Bitcoin Wallet or any other Airbitz SDK application.
48 |
49 |
In addition, the ABCDataStore object in the Airbitz ABCAccount object allows developers to store arbitrary Edge-Secured data on the user’s account which is automatically encrypted, automatically backed up, and automatically synchronized between the user’s authenticated devices.
50 |
51 |
To get started, you’ll first need an API key. Get one at http://developer.airbitz.co
52 |
53 |
Next create an xcode project and install CocoaPods in the project. Include ABC by adding the following lines to your ‘Podfile’.
54 |
55 |
target "nameOfYourProjectHere" do
56 | pod 'AirbitzCore', :http => "https://developer.airbitz.co/download/airbitz-core-objc-newest.tgz"
57 | end
58 |
59 |
60 |
Of course you’ll need to replace “nameOfYourProjectHere” with your actual Xcode project name.
61 |
62 |
Close the XCode project and then rerun ‘pod install’ from the directory with your Podfile.
63 |
64 |
Reopen the nameOfYourProjectHere.xcworkspace file from Xcode (not the xcproject file).
65 |
66 |
If you are using React Native, you’ll likely get a link error that you are missing some libraries. This is because React Native will overwrite linker flags set by Cocoapods. To fix, go to the project target Build Settings -> Other Linker Flags. Add “$(inherited)” to the linker flags.
67 |
68 |
And you’re done. You should be able to call into AirbitzCore. See below for code samples.
69 |
70 |
#import "AirbitzCore.h"
71 |
72 | // Global account object
73 | ABCAccount *gAccount;
74 |
75 | - (void) exampleMethod
76 | {
77 | // Create an account
78 | AirbitzCore *abc = [[AirbitzCore alloc] init:@"YourAPIKeyHere"];
79 | gAccount = [abc createAccount:@"myusername" password:@"MyPa55w0rd!&" pin:@"4283" delegate:self error:nil];
80 | // New account is auto logged in after creation
81 |
82 | // Use Airbitz Edge Security to write encrypted/backed up/synchronized data to the account
83 | [gAccount.dataStore dataWrite:@"myAppUserInfo" withKey:@"user_email" withValue:@"theuser@hisdomain.com"];
84 |
85 | // Read back the data
86 | NSMutableString *usersEmail = [[NSMutableString alloc] init];
87 | [gAccount.dataStore dataRead:@"myAppUserInfo" withKey:@"user_email" data:usersEmail];
88 |
89 | // usersEmail now contains "theuser@hisdomain.com"
90 |
91 | // Create a wallet in the user account
92 | ABCWallet *wallet = [abcAccount createWallet:@"My Awesome Wallet" currency:nil];
93 |
94 | // Logout
95 | [gAccount logout];
96 |
97 | // Log back in with full credentials
98 | gAccount = [abc loginWithPassword:@"myusername" password:@"MyPa55w0rd!&" delegate:self error:nil];
99 |
100 | // Logout
101 | [gAccount logout];
102 |
103 | // Log back in with PIN using completion handler codeblock
104 | [abc pinLogin:@"myusername" pin:@"4283" delegate:self complete:^(ABCAccount *account)
105 | {
106 | gAccount = account;
107 |
108 | } error:^(NSError *error) {
109 | NSLog(@"Argh! Error code: %d. Error string:%@", (int)error.code, error.userInfo[NSLocalizedDescriptionKey]);
110 | }];
111 |
112 | }
113 |
114 | // Delegate method called when wallets are loaded after a login
115 | - (void) abcAccountWalletLoaded:(ABCWallet *)wallet
116 | {
117 | // Create a bitcoin request
118 | ABCReceiveAddress *request = [wallet createNewReceiveAddress];
119 |
120 | // Put in some optional meta data into this request so incoming funds are automatically tagged
121 | request.metaData.payeeName = @"William Swanson"; // Name of the person receiving request
122 | request.metaData.category = @"Income:Rent"; // Category of payment. Auto tags category when funds come in
123 | request.metaData.notes = @"Rent payment for Jan 2016";
124 |
125 | // Put in an optional request amount and use fiat exchange rate conversion methods
126 | request.amountSatoshi = [gAccount.exchangeCache currencyToSatoshi:5.00 currencyCode:@"USD" error:nil];
127 |
128 | // Use the request results
129 | NSString *bitcoinAddress = request.address;
130 | NSString *bitcoinURI = request.uri;
131 | UIImage *bitcoinQRCode = request.qrCode;
132 |
133 | // Now go and display the QR code or send payment to address in some other way.
134 | }
135 |
136 | // Delegate method called when bitcoin is received
137 | - (void) abcAccountIncomingBitcoin:(ABCWallet *)wallet transaction:(ABCTransaction *)transaction;
138 | {
139 | NSLog(@"Yay, my wallet just received bitcoin. amount = %lld satoshis", transaction.amountSatoshi);
140 | }
141 |
142 |
143 |
144 |
145 |
146 |
147 |