Your team id can be found from Apple's developer portal in the top right corner of the Certificates, Identifiers & Profiles section.
Your bundle identifier can be found here
To get an API Key and configure your team and bundle ids, please go to the Developer Portal.
Once you've created an API key, please fill out the "Native Passkey Configuration" Section with your App Info described above. Please note that once entered, this information can take up to a day to be reflected by Apple. Ping us if you have any questions or if you would like to check in on the status of this
The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift
compiler.
Once you have your Swift package set up, adding CapsuleSwift as a dependency is as easy as adding it to the dependencies
value of your Package.swift
or the Package list in Xcode.
dependencies: [
.package(url: "https://github.com/capsule-org/swift-sdk.git", .upToNextMajor(from: "0.0.1"))
]
Normally you'll want to depend on the CapsuleSwift
target:
.product(name: "CapsuleSwift", package: "CapsuleSwift")
CapsuleSwift utilizes native passkeys for authentication and wallet information. In order to use native passkeys in your app you will need several things
Under Targets->AppName->Signing & Capabilities, click on the +Capability button.
From the prompt that appears, search for and select Associated Domains
Note: In order to add the associated domains capability to your project, you cannot use a personal team for the purposes of signing. If you are, you need to set up a company team with Apple.
In the associated domains section that appears after adding it, you will need to add two domains
- webcredentials:app.beta.usecapsule.com
- webcredentials:app.usecapsule.com
This will allow you to use passkeys that have been created on any app that uses the Capsule system, so if your users already have a Capsule wallet they will be able to use it in your app.
In order to set your API Key and desired environment in the example app, please copy the file locations at Configs/example into the root level of your project and name it EnvDebug for development, and EnvRelease for production. This is only an example of how to manage your environment variables.
CapsuleSwift provides an interface to Capsule services from within iOS applications using SwiftUI (Support for UIKit coming soon).
To configure the capsule instance, you will need to create an instance of the capsule object as well as the globally available authorizationController environment object. This will be needed in several functions later on. If you need an API Key, please reach out to the Capsule Team.
To create a user, you should first check in the provided email address exists, and if it does not then create it
Button("Sign Up") {
Task.init {
let userExists = try! await capsule.checkIfUserExists(email: email)
if userExists {
return
}
try! await capsule.createUser(email: email)
...
}
}
Upon success, the user should receive an email with a 6 digit verification pin. Call the verify function with the verification code acquired from this step. This will return a biometricsId which will be necessary to pass to the next function, generatePasskey.
Generate passkey takes in the authorizationController that was set up earlier. This is necessary to be able to allow the application to present the Passkey modals for creating and selecting a Passkey.
After generating the passkey, the last step is to create a wallet.
Button("Verify") {
Task.init {
let biometricsId = try! await capsule.verify(verificationCode: code)
try! await capsule.generatePasskey(email: email, biometricsId: biometricsId, authorizationController: authorizationController)
try! await capsule.createWallet(skipDistributable: false)
}
}
After the wallet has been created, it will be set in the Capsule object as a Published var.
To sign a message, all you need to do is pass in the id of the wallet you would like to use which can be obtained from the capsule.wallet property, and the text that you would like to sign. This will produce a messageSignature.
Button("Sign Message") {
Task.init {
let messageSignature = try! await capsule.signMessage(walletId: wallet.id, message: "Some message to sign")
...
}
}