mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
3baeb981d9
Moved the JobRunner into SessionUtilitiesKit so it can be used by SessionSnodeKit Exposed a 'sharedLokiProject' value on UserDefaults to remove the hard-coded group name used everywhere Added "blocking" job support for 'OnLaunch' and 'OnActive' jobs to the JobRunner (will retry until it succeeds) Added the UpdateProfilePicture and RetrieveDefaultOpenGroupRooms jobs
98 lines
3.8 KiB
Swift
98 lines
3.8 KiB
Swift
// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
|
|
|
|
import Foundation
|
|
import GRDB
|
|
|
|
enum _003_YDBToGRDBMigration: Migration {
|
|
static let identifier: String = "YDBToGRDBMigration"
|
|
|
|
static func migrate(_ db: Database) throws {
|
|
// MARK: - Identity keys
|
|
|
|
// Note: Want to exclude the Snode's we already added from the 'onionRequestPathResult'
|
|
var registeredNumber: String?
|
|
var seedHexString: String?
|
|
var userEd25519SecretKeyHexString: String?
|
|
var userEd25519PublicKeyHexString: String?
|
|
var userX25519KeyPair: Legacy.KeyPair?
|
|
|
|
Storage.read { transaction in
|
|
registeredNumber = transaction.object(
|
|
forKey: Legacy.userAccountRegisteredNumberKey,
|
|
inCollection: Legacy.userAccountCollection
|
|
) as? String
|
|
|
|
// Note: The 'seed', 'ed25519SecretKey' and 'ed25519PublicKey' were
|
|
// all previously stored as hex strings, so we need to convert them
|
|
// to data before we store them in the new database
|
|
seedHexString = transaction.object(
|
|
forKey: Legacy.identityKeyStoreSeedKey,
|
|
inCollection: Legacy.identityKeyStoreCollection
|
|
) as? String
|
|
|
|
userEd25519SecretKeyHexString = transaction.object(
|
|
forKey: Legacy.identityKeyStoreEd25519SecretKey,
|
|
inCollection: Legacy.identityKeyStoreCollection
|
|
) as? String
|
|
|
|
userEd25519PublicKeyHexString = transaction.object(
|
|
forKey: Legacy.identityKeyStoreEd25519PublicKey,
|
|
inCollection: Legacy.identityKeyStoreCollection
|
|
) as? String
|
|
|
|
userX25519KeyPair = transaction.object(
|
|
forKey: Legacy.identityKeyStoreIdentityKey,
|
|
inCollection: Legacy.identityKeyStoreCollection
|
|
) as? Legacy.KeyPair
|
|
}
|
|
|
|
// No need to continue if the user isn't registered
|
|
if registeredNumber == nil { return }
|
|
|
|
// If the user is registered then it's all-or-nothing for these values
|
|
guard
|
|
let seedHexString: String = seedHexString,
|
|
let userEd25519SecretKeyHexString: String = userEd25519SecretKeyHexString,
|
|
let userEd25519PublicKeyHexString: String = userEd25519PublicKeyHexString,
|
|
let userX25519KeyPair: Legacy.KeyPair = userX25519KeyPair
|
|
else {
|
|
// If this is a fresh install then we would have created all of the Identity
|
|
// values directly within the 'Identity' table so this is actually a valid
|
|
// case and we don't need to throw
|
|
if try Identity.fetchCount(db) == Identity.Variant.allCases.count {
|
|
return
|
|
}
|
|
|
|
throw GRDBStorageError.migrationFailed
|
|
}
|
|
print("RAWR publicKey \(userX25519KeyPair.publicKey.toHexString())")
|
|
try autoreleasepool {
|
|
// Insert the data into GRDB
|
|
try Identity(
|
|
variant: .seed,
|
|
data: Data(hex: seedHexString)
|
|
).insert(db)
|
|
|
|
try Identity(
|
|
variant: .ed25519SecretKey,
|
|
data: Data(hex: userEd25519SecretKeyHexString)
|
|
).insert(db)
|
|
|
|
try Identity(
|
|
variant: .ed25519PublicKey,
|
|
data: Data(hex: userEd25519PublicKeyHexString)
|
|
).insert(db)
|
|
|
|
try Identity(
|
|
variant: .x25519PrivateKey,
|
|
data: userX25519KeyPair.privateKey
|
|
).insert(db)
|
|
|
|
try Identity(
|
|
variant: .x25519PublicKey,
|
|
data: userX25519KeyPair.publicKey
|
|
).insert(db)
|
|
}
|
|
}
|
|
}
|