A swift package of KeystoneSDK. It's based on KeystoneSDK which is generated by keystone-sdk-rust
The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler.
To add KeystoneSDK as a dependency to your Xcode project, select File > Add Packages and enter URL: https://github.com/KeystoneHQ/keystone-sdk-ios.git.
Use generatePSBTExtend and parsePSBTExtend for the crypto-psbt-extend UR type. These APIs require the sdk-0.2.5 binary dependency or later.
Pass the raw PSBT bytes as Data:
import Foundation
import KeystoneSDK
let sdk = KeystoneSDK()
let psbtData = try Data(contentsOf: psbtFileURL) // URL of your PSBT file
// Litecoin. Display successive fragments as QR codes for the device to scan.
let encoder = try sdk.btc.generatePSBTExtend(psbt: psbtData, coinId: 2)
let qrFragment = encoder.nextPart()
// Call encoder.nextPart() again for each subsequent QR frame.
// Bitcoin: omit coinId, or pass 0. The coin field is omitted from the payload.
let bitcoinEncoder = try sdk.btc.generatePSBTExtend(psbt: psbtData)| Coin | coinId |
|---|---|
| Bitcoin | 0 (default) |
| Litecoin | 2 |
| Dogecoin | 3 |
| Dash | 5 |
| Bitcoin Cash | 145 |
coinId is an Int32. Unsupported values throw KeystoneError.generatePSBTError.
Reuse the same KeystoneSDK instance across frames so the decoder can assemble multipart URs:
// Call for each scanned QR string, using the sdk instance above.
func receivePSBTExtendFragment(_ qrString: String) throws -> PSBTExtend? {
let decoded = try sdk.decodeQR(qrCode: qrString)
guard let ur = decoded.ur else {
return nil // More fragments are needed.
}
defer { sdk.resetQRDecoder() }
return try sdk.btc.parsePSBTExtend(ur: ur)
}
// Inside your scanner callback:
if let result = try receivePSBTExtendFragment(scannedQRCode) {
let psbt: Data = result.psbt
let coinId: Int32? = result.coinId // nil means Bitcoin.
// Pass psbt and coinId to your transaction handling code.
}If you already have a decoded UR, call sdk.btc.parsePSBTExtend(ur: ur) directly. A different UR type throws QRCodeError.unexpectedQRCode; an invalid Extend payload throws KeystoneError.parsePSBTError.
For ordinary crypto-psbt URs, continue using generatePSBT(psbt:) and parsePSBT(ur:).
-
Install Rust https://www.rust-lang.org/learn/get-started
-
Clone the rust repo.
git clone https://github.com/KeystoneHQ/keystone-sdk-rust
cd keystone-sdk-rust- Install ios targets
rustup target add aarch64-apple-ios x86_64-apple-ios aarch64-apple-ios-sim- Generate XCFramework
Make sure the header file keystone-sdk-rust/include/URRegistryFFI/lib_ur_registry_ffi.h is up to date.
make generate_xcframework- Replace the
URRegistryFFI.xcframeworkinURRegistry/Libraryfrom thetargetbuild folder