SwiftUI component library for quickly integrating Aegis signer URL scheme method.
In Xcode:
- Project β Package Dependencies β "+"
- Enter:
https://github.com/ZharlieW/AegisConnectKit.git - Choose version rule β Add Package
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>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)
}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)")
}
}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)
}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
)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.
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
)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)")
}
}AegisConnectButton(
clientPubKey: "your_client_public_key",
secret: "your_secret",
title: "Use Aegis Logo",
useAegisLogo: true,
backgroundColor: .blue
) { result in
handleResult(result)
}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)")
}
}
}MIT License - see LICENSE file for details.