Skip to main content
Class Definition
public class FirebaseStorage: Storage, PortalStorage
FirebaseStorage handles storing and retrieving backup encryption keys using Firebase Authentication. It communicates with Portal’s secure enclave using Firebase ID tokens for authentication. Initializer
public init(
  getToken: @escaping () async throws -> String?
)
Parameters
  • getToken: A callback that returns a fresh Firebase ID token. This is called before each request to the secure enclave to ensure the token is valid. The callback should call Firebase’s getIDToken() method internally. Return nil if no user is signed in.
Errors FirebaseStorage can throw the following errors:
  • FirebaseStorageError.noApiKey: The client API key has not been set on the FirebaseStorage instance. This means the storage was not registered via portal.registerBackupMethod().
  • FirebaseStorageError.tokenUnavailable: The getToken callback returned nil. Ensure the user is signed in to Firebase before performing backup or recovery.
  • FirebaseStorageError.unexpectedResponse(String): The secure enclave returned an unexpected response.
  • FirebaseStorageError.requestFailed(underlying: Error): A non-401 request to the secure enclave failed. The underlying error contains details about the failure.
Example Usage
import FirebaseAuth
import PortalSwift

// Create a FirebaseStorage instance
let firebaseStorage = FirebaseStorage(
  getToken: {
    guard let user = Auth.auth().currentUser else {
      return nil
    }
    return try await user.getIDToken(forcingRefresh: true)
  }
)

// Register it with Portal
portal.registerBackupMethod(.Firebase, withStorage: firebaseStorage)

// Now you can use .Firebase for backup and recovery
let (cipherText, storageCallback) = try await portal.backupWallet(.Firebase)
try await storageCallback()
Related Documentation