Signal-iOS/SignalServiceKit/SecureValueRecovery/AccountEntropyPool/AccountEntropyPool.swift
2025-08-26 12:00:04 -07:00

40 lines
1.1 KiB
Swift

//
// Copyright 2025 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
//
import Foundation
public import LibSignalClient
public struct AccountEntropyPool: Codable {
public enum Constants {
public static let byteLength: Int = 64 /* bytes */
}
private let key: String
public var rawData: String { key }
public init() {
self.key = LibSignalClient.AccountEntropyPool.generate()
}
public init(key: String) throws {
guard LibSignalClient.AccountEntropyPool.isValid(key) else {
throw OWSAssertionError("Invalid entropy pool key")
}
self.key = key
}
// Derived Keys
public func getMasterKey() -> MasterKey {
// Force unwrap here. At this point, the AEP value should either have been validated by
// LibSignal on init, or generated by LibSignal, so should correctly generate a MasterKey.
return try! MasterKey(data: try! LibSignalClient.AccountEntropyPool.deriveSvrKey(key))
}
public func getBackupKey() -> BackupKey {
return try! LibSignalClient.AccountEntropyPool.deriveBackupKey(key)
}
}