// Basic usage
do {
try portal.setPassword("mySecurePassword123!")
} catch {
print("Error setting password: \(error)")
}
// Complete setup with password backup
do {
// First register the password storage method
let passwordStorage = PasswordStorage()
portal.registerBackupMethod(.Password, withStorage: passwordStorage)
// Set the password
try portal.setPassword("mySecurePassword123!")
// Now you can use password-based backup
let backup = try await portal.backupWallet(.Password) { status in
switch status.status {
case .readingShare:
print("Reading share...")
case .encryptingShare:
print("Encrypting with password...")
case .storingShare:
print("Storing encrypted backup...")
case .done:
print("Backup complete!")
default:
break
}
}
// Complete the backup process
try await backup.storageCallback()
} catch {
print("Error in password backup process: \(error)")
}
// Example with password recovery
do {
// Set up password for recovery
try portal.setPassword("mySecurePassword123!")
// Recover wallet using password
let recovered = try await portal.recoverWallet(
.Password,
withCipherText: backupCipherText
) { status in
print("Recovery status: \(status)")
}
print("Recovered wallet with address: \(recovered.ethereum)")
} catch {
print("Error in password recovery process: \(error)")
}