mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.5 KiB
Swift
39 lines
1.5 KiB
Swift
|
|
@objc(SNClosedGroupsV2Migration)
|
|
public class ClosedGroupsV2Migration : OWSDatabaseMigration {
|
|
|
|
@objc
|
|
class func migrationId() -> String {
|
|
return "006"
|
|
}
|
|
|
|
override public func runUp(completion: @escaping OWSDatabaseMigrationCompletion) {
|
|
self.doMigrationAsync(completion: completion)
|
|
}
|
|
|
|
private func doMigrationAsync(completion: @escaping OWSDatabaseMigrationCompletion) {
|
|
let publicKeys = Storage.shared.getUserClosedGroupPublicKeys()
|
|
var keyPairs: [ECKeyPair] = []
|
|
for publicKey in publicKeys {
|
|
guard let privateKey = Storage.shared.getClosedGroupPrivateKey(for: publicKey) else { continue }
|
|
do {
|
|
let keyPair = try ECKeyPair(publicKeyData: Data(hex: publicKey.removing05PrefixIfNeeded()), privateKeyData: Data(hex: privateKey))
|
|
keyPairs.append(keyPair)
|
|
} catch {
|
|
// Do nothing
|
|
}
|
|
}
|
|
Storage.write(with: { transaction in
|
|
for publicKey in publicKeys {
|
|
Storage.shared.addClosedGroupPublicKey(publicKey, using: transaction)
|
|
}
|
|
for keyPair in keyPairs {
|
|
Storage.shared.addClosedGroupEncryptionKeyPair(keyPair, for: keyPair.hexEncodedPublicKey, using: transaction) // In this particular case keyPair.publicKey == groupPublicKey
|
|
}
|
|
self.save(with: transaction) // Intentionally capture self
|
|
}, completion: {
|
|
completion()
|
|
})
|
|
}
|
|
}
|