Skip to content

ZharlieW/AegisConnectKit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

19 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AegisConnectKit

Swift Platform License

SwiftUI component library for quickly integrating Aegis signer URL scheme method.

πŸš€ Quick Integration

1. Install Dependencies

In Xcode:

  1. Project β†’ Package Dependencies β†’ "+"
  2. Enter: https://github.com/ZharlieW/AegisConnectKit.git
  3. Choose version rule β†’ Add Package

2. Configure URL Scheme

Key Step: Configure custom URL scheme in Info.plist to redirect back from Aegis signer to your app:

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>yourapp</string>
        </array>
    </dict>
</array>

3. Handle Callbacks

Handle URL callbacks redirected back from Aegis signer:

func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
    guard let url = URLContexts.first?.url else { return }
    AegisConnectKit.shared.handleOpenURL(url)
}

πŸ“± Integration Options

Option 1: Use Button Component (Recommended)

Click the button to automatically redirect users to Aegis signer for authentication:

import SwiftUI
import AegisConnectKit

AegisConnectButton(
    clientPubKey: "your_client_public_key",
    secret: "your_secret"
) { result in
    switch result {
    case .success(let credential):
        print("βœ… Login successful: \(credential)")
        // Get relay and connect
        if let relay = credential.queryParameters["relay"] {
            print("πŸ“‘ Connecting to relay: \(relay)")
            // Implement your relay connection logic here
        }
    case .failure(let error):
        print("❌ Login failed: \(error)")
    }
}

Option 2: Direct Method Call

Manually trigger redirection to Aegis signer:

func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
    guard let url = URLContexts.first?.url else { return }
    AegisConnectKit.shared.handleOpenURL(url)
}

πŸ“š API Reference

Direct Authentication Method

let credential = try await AegisConnectKit.shared.authenticate(
    clientPubKey: "your_client_public_key",
    secret: "your_secret",
    name: "Your App Name",           // Optional
    url: "https://yourapp.com",      // Optional
    image: "https://yourapp.com/icon.png",  // Optional
    scheme: "yourapp"                // Optional, auto-reads from Info.plist
)

Credential Structure

The returned Credential contains relay connection information:

public struct Credential: Codable {
    public let callbackURL: String           // Callback URL path
    public let fullCallbackURL: String       // Complete callback URL
    public let queryParameters: [String: String]  // Relay connection parameters
}

Important: After authentication, you must use the information in queryParameters to connect to the relay and complete the NIP-46 flow.

Button Component Parameters

AegisConnectButton(
    // Required parameters
    clientPubKey: String,            // Client public key
    secret: String,                  // Secret key
    
    // Optional parameters
    scheme: String? = nil,           // URL scheme
    url: String = "",                // App URL
    image: String = "",              // App icon URL
    name: String? = nil,             // App name
    title: String = "Connect with Aegis",  // Button title
    useAegisLogo: Bool = false,      // Whether to use Aegis logo
    backgroundColor: Color = .white,  // Background color
    onResult: @escaping (Result<Credential, Error>) -> Void = { _ in }  // Result callback
)

πŸ’‘ Examples

Basic Usage

AegisConnectButton(
    clientPubKey: "your_client_public_key",
    secret: "your_secret"
) { result in
    handleAuthenticationResult(result)
}

func handleAuthenticationResult(_ result: Result<Credential, Error>) {
    switch result {
    case .success(let credential):
        // Get relay and connect
        if let relay = credential.queryParameters["relay"] {
            print("πŸ“‘ Connecting to relay: \(relay)")
            // Implement your relay connection logic here
        }
    case .failure(let error):
        print("❌ Authentication failed: \(error)")
    }
}

Custom Styling

AegisConnectButton(
    clientPubKey: "your_client_public_key",
    secret: "your_secret",
    title: "Use Aegis Logo",
    useAegisLogo: true,
    backgroundColor: .blue
) { result in
    handleResult(result)
}

Direct Method Call

Button("Connect Aegis") {
    Task {
        do {
            let credential = try await AegisConnectKit.shared.authenticate(
                clientPubKey: "your_client_public_key",
                secret: "your_secret",
                name: "Your App Name"
            )
            print("βœ… Login successful: \(credential)")
            // Get relay and connect
            if let relay = credential.queryParameters["relay"] {
                print("πŸ“‘ Connecting to relay: \(relay)")
                // Implement your relay connection logic here
            }
        } catch {
            print("❌ Login failed: \(error)")
        }
    }
}

πŸ“„ License

MIT License - see LICENSE file for details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages