Swift SDK

The Fyno TOTP SDK for iOS provides secure Time-based One-Time Password (TOTP) generation and tenant management. It supports tenant enrollment, secure secret storage using the iOS Keychain, configurable TOTP parameters, and OTP generation compliant with RFC 6238.

Module Name: FynoTOTP
Minimum iOS Version: iOS 13
Target iOS Version: iOS 16+
Language: Swift

Table of Contents

  1. Installation
  2. Core Components
  3. API Reference
  4. Usage Examples
  5. Data Models
  6. Error Handling
  7. Security Considerations

Installation

CocoaPods

Add the dependency to your Podfile:

1pod 'FynoTOTP'

Then run:

$pod install

Core Components

FynoTOTP Class

The main entry point for all SDK operations.

Responsibilities:

  • SDK initialization
  • Tenant registration and revocation
  • Secure secret storage using Keychain
  • TOTP generation

Initializer:

1let fynoTotp = FynoTOTP()

API Reference

initFynoConfig

Initializes the SDK with workspace and user identifiers.

1func initFynoConfig(
2 wsid: String,
3 distinctId: String,
4 completion: @escaping (Result<Void, Error>) -> Void
5)

registerTenant

Registers a tenant and securely stores the TOTP secret.

1func registerTenant(
2 tenantId: String,
3 tenantLabel: String,
4 totpToken: String,
5 completion: @escaping (Result<Void, Error>) -> Void
6)

setConfig

Sets the TOTP configuration for a tenant.

1func setConfig(
2 tenantId: String,
3 config: TotpConfig,
4 completion: @escaping (Result<Void, Error>) -> Void
5)

getTotp

Generates and retrieves the current TOTP code.

1func getTotp(
2 tenantId: String,
3 completion: @escaping (Result<String?, Error>) -> Void
4)

deleteTenantData

Deletes all tenant data and the stored secret.

1func deleteTenantData(tenantId: String)

Data Models

TotpConfig

1struct TotpConfig: Codable {
2 let tenant_name: String
3 let digits: Int
4 let algorithm: String
5 let period: Int
6}

Error Handling

FynoError

1enum FynoError: Error {
2 case invalidSecret
3 case invalidSecretEncoding
4 case unsupportedAlgorithm
5 case hashingFailed
6 case base64DecodeFailed
7 case secretDecodeFailed
8}

Security Considerations

  • Secrets stored in iOS Keychain
  • RFC 6238 compliant TOTP generation
  • HMAC SHA1 / SHA256 / SHA512 support

Changelog

Version 1.0.0

  • Initial iOS TOTP release