Skip to content

zerosettle/ZeroSettleKit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ZeroSettleKit

A Swift package for iOS that enables seamless fiat-to-crypto onboarding with phone authentication, Apple Pay, and embedded wallets.

Features

  • 📱 Phone Authentication - SMS-based login with Privy SDK
  • 🔐 Embedded Wallets - Automatic Solana wallet creation
  • 💳 Apple Pay → Crypto - Coinbase Commerce integration for USDC onramp
  • ⛓️ Multi-Chain Ready - Designed to support multiple blockchains
  • 🎨 Customizable UI - Optional SwiftUI components with theming
  • 🔌 Protocol-Based - Easily swap payment processors

Installation

Swift Package Manager

Add ZeroSettleKit to your project:

dependencies: [
    .package(url: "https://github.com/your-org/ZeroSettleKit.git", from: "0.1.0")
]

Or in Xcode:

  1. File → Add Packages...
  2. Enter the repository URL
  3. Select version and add to your target

Quick Start

1. Configure ZeroSettleKit

import ZeroSettleKit

// Create a Coinbase payment processor
let coinbaseProcessor = CoinbasePaymentProcessor(
    apiKeyId: "your-coinbase-api-key-id",
    apiKeySecret: "your-coinbase-api-secret",
    environment: .production
)

// Configure ZeroSettle
let config = ZeroSettleConfig(
    privyAppId: "your-privy-app-id",
    privyClientId: "your-privy-client-id",
    supportedChains: [.solana, .base],
    paymentProcessor: coinbaseProcessor,
    defaultNetwork: .base,
    partnerAppId: 2 // Replace with your partner app ID
)

// Initialize the manager
let zeroSettle = ZeroSettleManager(config: config)
zeroSettle.delegate = self

2. Initialize (in your App or Scene)

@main
struct MyApp: App {
    @StateObject private var zeroSettle: ZeroSettleManager

    init() {
        let config = ZeroSettleConfig(...)
        _zeroSettle = StateObject(wrappedValue: ZeroSettleManager(config: config))
    }

    var body: some Scene {
        WindowGroup {
            ContentView()
                .environmentObject(zeroSettle)
                .environmentObject(zeroSettle.authManager)
                .task {
                    await zeroSettle.initialize()
                }
        }
    }
}

3. Authenticate Users

// Send OTP
try await zeroSettle.sendOTPCode(to: "+14155552671")

// Verify OTP and login
try await zeroSettle.loginWithOTP(code: "123456", phoneNumber: "+14155552671")

// User now has an embedded Solana wallet!
print("Wallet: \(zeroSettle.walletAddress)")

4. Add Funds

// Initiate funding session
let session = try await zeroSettle.initiateFunding(
    amount: Decimal(3.00),
    currency: "USD"
)

// Load session.paymentURL in a WKWebView
// User completes Apple Pay checkout
// Coinbase sends USDC to user's wallet

5. Fetch the latest payout table

let payoutTable = try await zeroSettle.fetchLatestPayoutTable()
for tier in payoutTable.tiers {
    print("\(tier.guessesUsed) guesses → \(tier.multiplier)x")
}

partnerAppId defaults to 2 (WordPlay) but you can configure it via ZeroSettleConfig to target your own app. If your deployment requires an Authorization header, provide a closure through partnerAuthTokenProvider to return a bearer token at request time.

Architecture

ZeroSettleKit
├── Core/
│   ├── ZeroSettleManager.swift       # Main facade
│   ├── ZeroSettleConfig.swift        # Configuration
│   └── ZeroSettleDelegate.swift      # Event callbacks
│
├── Authentication/
│   └── AuthenticationManager.swift   # Privy integration
│
├── Funding/
│   ├── PaymentProcessor.swift        # Protocol
│   └── Coinbase/
│       ├── CoinbasePaymentProcessor.swift
│       ├── CoinbaseJWTGenerator.swift
│       └── CoinbaseOnrampEventHandler.swift
│
├── Models/
│   └── BlockchainModels.swift        # Shared models
│
└── UI/ (coming soon)
    └── Components/

Protocol-Based Design

ZeroSettleKit uses protocols to support multiple payment processors:

public protocol PaymentProcessor {
    var supportedMethods: [PaymentMethod] { get }

    func initiateFunding(
        amount: Decimal,
        currency: String,
        destination: String,
        network: BlockchainNetwork
    ) async throws -> FundingSession
}

Supported Processors

  • Coinbase Commerce (Apple Pay, Credit/Debit Cards)
  • 🔜 Stripe (Coming soon)
  • 🔜 MoonPay (Coming soon)
  • 🔜 Custom (Implement your own!)

Delegate Pattern

Implement ZeroSettleDelegate to receive events:

extension MyViewController: ZeroSettleDelegate {
    func didAuthenticate(userId: String, wallet: WalletInfo) {
        print("✅ User \(userId) authenticated with wallet \(wallet.address)")
    }

    func didCompleteFunding(amount: Decimal, currency: String, transactionHash: String?) {
        print("💰 Added \(amount) \(currency)")
    }

    func didFailFunding(error: Error) {
        print("❌ Funding failed: \(error)")
    }
}

Multi-Chain Support

ZeroSettleKit is designed to support multiple blockchains:

public enum BlockchainNetwork: String, Codable {
    case ethereum
    case base
    case arbitrum
    case optimism
    case polygon
    case solana
}

Currently, Privy SDK supports Solana embedded wallets. EVM chain support coming soon!

Customization

Theming

let theme = ZeroSettleTheme(
    primaryColor: "#00FF00",
    secondaryColor: "#FFFFFF",
    backgroundColors: ["#000000", "#1A1A1A"],
    buttonCornerRadius: 12
)

let config = ZeroSettleConfig(
    ...
    theme: theme
)

Default Funding Amounts

let config = ZeroSettleConfig(
    ...
    defaultFundingAmounts: [100, 500, 1000, 2000] // Cents: $1, $5, $10, $20
)

Requirements

  • iOS 15.0+
  • Swift 5.9+
  • Xcode 15.0+

Dependencies

Getting API Keys

Privy

  1. Sign up at privy.io
  2. Create a new app
  3. Copy your App ID and Client ID

Coinbase Commerce

  1. Sign up at Coinbase Developer Platform
  2. Create API credentials
  3. Copy your API Key ID and Secret

Security

⚠️ Never commit API credentials to your repository!

Use environment variables or a secure configuration:

// ❌ DON'T do this
let apiKey = "your-secret-key"

// ✅ DO this
let apiKey = ProcessInfo.processInfo.environment["COINBASE_API_KEY"] ?? ""

Example App

See the Example/ directory for a complete implementation.

Roadmap

  • Core authentication (Privy)
  • Coinbase payment processor
  • Protocol-based architecture
  • SwiftUI UI components
  • Stripe payment processor
  • EVM chain support
  • Transaction monitoring
  • Balance tracking
  • DocC documentation
  • Unit tests
  • Example app

License

MIT License - See LICENSE file for details

Contributing

Contributions welcome! Please read CONTRIBUTING.md first.

Support


Built with ❤️ by ZeroSettle

About

The official iOS SDK for ZeroSettle

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages