     return nil
 }
 
-func getAuthKey() -> BRKey {
-    return BRKey.init(privateKey: BRWalletManager.sharedInstance().authPrivateKey)
+func getAuthKey() -> BRKey? {
+    if let manager = BRWalletManager.sharedInstance(), authKey = manager.authPrivateKey {
+        return BRKey(privateKey: authKey)
+    }
+    return nil
 }
 
 func getDeviceId() -> String {

            mutableRequest.setValue(httpDateNow(), forHTTPHeaderField: "Date")
        }
        do {
            if let tokenData = try BRKeychain.loadDataForUserAccount(userAccountKey), token = tokenData["token"] {
                self.log("token data \(tokenData)")
                let sha = buildSigningString(mutableRequest).dataUsingEncoding(NSUTF8StringEncoding)!.SHA256_2()
                let sig = getAuthKey().compactSign(sha).base58String()
                mutableRequest.setValue("bread \(token):\(sig)", forHTTPHeaderField: "Authorization")
            }
        } catch let e as BRKeychainError {

    
    // retrieve a token and save it in the keychain data for this account
    func getToken(handler: (NSError?) -> Void) -> Void {
        if getAuthKey() == nil {
            return handler(NSError(domain: BRAPIClientErrorDomain, code: 500, userInfo: [
                NSLocalizedDescriptionKey: NSLocalizedString("Wallet not ready", comment: "")]))
        }
        let req = NSMutableURLRequest(URL: url("/token"))
        req.HTTPMethod = "POST"
        req.setValue("application/json", forHTTPHeaderField: "Content-Type")
        req.setValue("application/json", forHTTPHeaderField: "Accept")
        let reqJson = [
            "pubKey": getAuthKey()!.publicKey.base58String(),
            "deviceID": getDeviceId()
        ]
        do {
