Skip to content
Aaron Voisine edited this page Sep 25, 2015 · 12 revisions

breadwallet-core getting started guide

New wallet creation:
  1. If the native secure keystore is verified as being available, and it does not contain a master public key, then present the user with the option to create a new wallet.

  2. Using a native source of entropy suitable for cryptographic use, obtain 128bits of random data.

  3. Use BRBIP39Encode() to encode this 128bits of data as a 12 word recovery phrase.

  4. Store the resulting recovery phrase in the native secure keystore.

  5. Store any appropriate wallet authentication information in the secure keystore as well, such as a user selected passcode.

  6. Use BIP39DeriveKey() to derive a master private key from the recovery phrase, feed this to BIP32MasterPubKey() to get the master pubkey, and store the master pubkey in the secure keystore.

  7. Store the timestamp when the wallet was created in the secure keystore.

The creation time and master pubkey should be available to the wallet app without user authentication, so that it can be used for background network syncing, and/or syncing immediately on app launch prior to the user being authenticated. It's desirable to use the keystore so that it will be removed in any situation where the keystore data goes missing, such as a backup/restore to a different device that fails to migrate keystore data.

Existing wallet startup:
  1. Retrieve the master pubkey and wallet creation time from the native secure keystore.

  2. Create an array of BRTransaction structs from all transactions in the local data store.

  3. Create a BRWallet struct with BRWalletNew(), using the master pubkey, transaction array, and a callback that retrieves the master private key (wallet seed) from the secure keystore (only after successfully authenticating the user).

  4. Use BRWalletSetCallbacks() to setup callback functions to be notified of balance changes, and to add/update/remove transactions from the local data store.

  5. Create arrays of BRPeer and BRMerkleBlock structs from peers and blocks in the local data store.

  6. Create a BRPeerManager struct with BRPeerManagerNew() using the wallet struct, creation time, and arrays of peers and merkleblocks.

  7. Use BRPeerManagerSetCallbacks() to setup callback functions to be notified of network syncing start/success/failure, of changes to transaction status (when a new block arrives), to store peers and blocks in the local data store, and a callback function for the peer manager to check the current status of the network connection.

  8. Call BRPeerManagerConnect() to initiate connection and syncing with the bitcoin network.

  9. Call BRPeerManagerSyncProgress() to monitor syncing progress.

Transaction creation and broadcast:
  1. Call BRWalletCreateTransaction() with a payment address and amount.

  2. Call BRWalletFeeForTx() to get the amount of the bitcoin network fee, and BRWalletAmountSentByTx() and BRWalletAmountReceivedByTx() for the final total.

  3. Call BRWalletSignTransaction() with an authorization prompt string containing all the information the user needs to decide to either confirm or cancel the transaction, such as recipient name, bitcoin address, and amount/fee/total.

  4. Call BRPeerManagerPublishTx() to broadcast the signed transaction to the bitcoin network.

  5. Call BRPeerManagerRelayCount() with the transaction hash to monitor network propagation.

Clone this wiki locally