Photon is an SDK for managing encrypted private keys in the cloud.
For the benefits and threat model on storing secrets on iCloud please see here.
There are 3 components to Photon:
- key server run by the wallet provider
- stores high entropy encryption keys and provides server side security such as rate limited PIN authentication
- The users iCloud
- The bitcoin wallet
- this is the client application the user interacts with This SDK is for bitcoin wallet developers who want to implement Photon key management in their app.
This SDK should be used within a iOS wallet to:
- generate encryption keys
- encrypt private keys
- interact with the users iCloud account
- interact with your keyserver
A demo Swift iOS application will be available in September, which documents how the Photon components work together in a final product. The application will be open source.
Not yet implemented.
Not yet implemented.
Copy the contents of BTCPhotonKit to your xcode project.
-
Enable the Cloudkit capability within xcode settings
Follow Apple documentaion or follow the images below
Ensure the server is running: Photon KeyServer
let secret = "bottom evoke mask jar patch distance force invite senior soccer allow youth normal beauty joke live rebel charge merge episode abandon donor screen video"
let encryptedSecret = secret.data(using: .utf8)
var cha = ChaCha()
let key: SymmetricKey = cha.generateKey()
let keyAsData = key.withUnsafeBytes({
return Data(Array($0))
})
// sealedBox is the encrypted seed/secret
let sealedBox = try! cha.encrypt(secret: encryptedSecret!, key: keyAsData)
let keyServer = Keyserver("http://localhost:8000")
keyServer.createKey(pin: pin) { (result) in
if case .success(let data) = result {
// yay, it worked!
}
}
let cloudStore = CloudStore()
cloudStore.putKey(keyId: keyId, ciphertext: ciphertext) { (result) in
if case .success(let status) = result {
response = status
}
}
let cloudStore = CloudStore()
let keyBackUp = Keybackup("server_path", cloudStore: cloudStore)
keyBackUp.restoreBackup(pin: pin) { result in
if case .success(let data) = result {
restoreBackupResponse = data
}
}
let cloudStore = CloudStore()
let keyBackUp = Keybackup("server_path", cloudStore: cloudStore)
keyBackUp.changePin(pin: pin, newPin: "") { result in
if case .success(let data) = result {
changePinResponse = data
}
}
let cloudStore = CloudStore()
let keyBackUp = Keybackup("server_path", cloudStore: cloudStore)
keyBackUp.registerPhone(userId: phone, pin: pin) { result in
if case .success(let data) = result {
registerPhoneResponse = data
}
}
let cloudStore = CloudStore()
let keyBackUp = Keybackup("server_path", cloudStore: cloudStore)
keyBackUp.registerEmail(userId: email, pin: pin) { result in
if case .success(let data) = result {
emailResponse = data
}
}
let cloudStore = CloudStore()
let keyBackUp = Keybackup("server_path", cloudStore: cloudStore)
keyBackUp.initPinReset(userId: phone ) { result in
if case .success(let data) = result {
pinResponse = data
}
}
let cloudStore = CloudStore()
let keyBackUp = Keybackup("server_path", cloudStore: cloudStore)
keyBackUp.createBackup(data: ciphertext, pin: pin) { result in
if case .success(let data) = result {
createBackupResponse = data
}
}
let cloudStore = CloudStore()
let keyBackUp = Keybackup("server_path", cloudStore: cloudStore)
keyBackUp.restoreBackup(pin: pin) { result in
if case .success(let data) = result {
restoreBackupResponse = data
}
}
To run test checkout this library open BTCPhotonKit.xcodeproj select Product > Test (⌘ + U )