Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion MIRACLTrust.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Pod::Spec.new do |s|
s.name = "MIRACLTrust"
s.summary = "MIRACL Trust SDK for iOS"
s.requires_arc = true
s.version = "1.4.0"
s.version = "1.5.0"
s.license = { :type => "Apache2", :file => "LICENSE" }
s.author = { "MIRACL" => "[email protected]" }
s.homepage = "https://github.com/miracl/trust-sdk-ios"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ struct Authenticator: Sendable, AuthenticatorBlueprint {
if let clientErrorData, clientErrorData.code == MPINID_EXPIRED || clientErrorData.code == EXPIRED_MPINID {
let user = user.revoke()

try? userStorage.update(user: user)
try? userStorage.update(user: user.toUserDTO())

callCompletionHandler(with: AuthenticationError.revoked)
return
Expand Down Expand Up @@ -225,7 +225,7 @@ struct Authenticator: Sendable, AuthenticatorBlueprint {
case MPINID_REVOKED, REVOKED_MPINID:
let user = user.revoke()

try? userStorage.update(user: user)
try? userStorage.update(user: user.toUserDTO())

callCompletionHandler(with: AuthenticationError.revoked)
return
Expand Down
8 changes: 5 additions & 3 deletions MIRACLTrust/MIRACLTrust-Sources/MIRACLTrust.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import Foundation
// MARK: Public properties

@objc public var users: [User] {
userStorage.all()
userStorage.all().map {
$0.toUser()
}
}

@objc public var projectId: String
Expand Down Expand Up @@ -847,15 +849,15 @@ import Foundation
/// - userId: id of the user. Can be email or any other string.
/// - Returns: User object from the database. Returns nil if there is no such object in the storage.
@objc public func getUser(by userId: String) -> User? {
userStorage.getUser(by: userId, projectId: projectId)
userStorage.getUser(by: userId, projectId: projectId)?.toUser()
}

// MARK: Identities Removal

/// Delete a registered user.
/// - Parameter user: object that needs to be deleted.
@objc public func delete(user: User) throws {
try userStorage.delete(user: user)
try userStorage.delete(user: user.toUserDTO())
}

// MARK: Private methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct PushNotificationAuthenticator: Sendable {
return
}

guard let user = userStorage.getUser(by: userId, projectId: projectId) else {
guard let user = userStorage.getUser(by: userId, projectId: projectId)?.toUser() else {
callCompletionHandler(
authenticated: false,
error: AuthenticationError.userNotFound
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ final class Registrator: Sendable {
category: .registration
)

try userStorage.update(user: user)
try userStorage.update(user: user.toUserDTO())

DispatchQueue.main.async {
self.completionHandler(user, nil)
Expand All @@ -310,7 +310,7 @@ final class Registrator: Sendable {
category: .registration
)

try userStorage.add(user: user)
try userStorage.add(user: user.toUserDTO())

DispatchQueue.main.async {
self.completionHandler(user, nil)
Expand Down
2 changes: 1 addition & 1 deletion MIRACLTrust/MIRACLTrust-Sources/Signing/Signer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ struct Signer: Sendable {
logOperation(operation: LoggingConstants.signingExecution)

// User could be updated from WaM.
let user = userStorage.getUser(by: user.userId, projectId: user.projectId) ?? user
let user = userStorage.getUser(by: user.userId, projectId: user.projectId)?.toUser() ?? user
let timestamp = Date()

guard let publicKey = user.publicKey else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ final class SQLiteUserStorage: NSObject, UserStorage {
}
}

func add(user: User) throws {
func add(user: UserDTO) throws {
let insertUser = """
INSERT INTO
User(userId, projectId, revoked, pinLength, mpinId, token, dtas, publicKey) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
Expand Down Expand Up @@ -119,7 +119,7 @@ final class SQLiteUserStorage: NSObject, UserStorage {
}
}

func delete(user: User) throws {
func delete(user: UserDTO) throws {
let deleteUser = """
DELETE FROM User WHERE userId = ? AND projectId = ?
"""
Expand All @@ -136,7 +136,7 @@ final class SQLiteUserStorage: NSObject, UserStorage {
)
}

func update(user: User) throws {
func update(user: UserDTO) throws {
let updateUser = """
UPDATE User
SET revoked = ?, pinLength = ? , mpinId = ?, token = ?, dtas = ?, publicKey = ?
Expand Down Expand Up @@ -178,13 +178,13 @@ final class SQLiteUserStorage: NSObject, UserStorage {
)
}

func all() -> [User] {
func all() -> [UserDTO] {
let selectAllUsers = """
SELECT * FROM User
"""

do {
var users = [User]()
var users = [UserDTO]()
try sqliteHelper.select(
statement: selectAllUsers,
bindingsBlock: nil,
Expand Down Expand Up @@ -223,7 +223,7 @@ final class SQLiteUserStorage: NSObject, UserStorage {
publicKey = data
}

let iteratedUser = User(
let iteratedUser = UserDTO(
userId: userId,
projectId: projectId,
revoked: revoked,
Expand All @@ -242,13 +242,13 @@ final class SQLiteUserStorage: NSObject, UserStorage {
}
}

func getUser(by userId: String, projectId: String) -> User? {
func getUser(by userId: String, projectId: String) -> UserDTO? {
let selectUserByUserIdAndProjectId = """
SELECT * FROM User WHERE userId = ? AND projectId = ?
"""

do {
var user: User?
var user: UserDTO?
try sqliteHelper.select(
statement: selectUserByUserIdAndProjectId,
bindingsBlock: { statement in
Expand Down Expand Up @@ -291,7 +291,7 @@ final class SQLiteUserStorage: NSObject, UserStorage {

publicKey = data
}
user = User(
user = UserDTO(
userId: userId,
projectId: projectId,
revoked: revoked,
Expand Down
15 changes: 15 additions & 0 deletions MIRACLTrust/MIRACLTrust-Sources/User Storage/User.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,18 @@ import Foundation
)
}
}

extension User {
func toUserDTO() -> UserDTO {
UserDTO(
userId: userId,
projectId: projectId,
revoked: revoked,
pinLength: pinLength,
mpinId: mpinId,
token: token,
dtas: dtas,
publicKey: publicKey
)
}
}
72 changes: 72 additions & 0 deletions MIRACLTrust/MIRACLTrust-Sources/User Storage/UserDTO.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import Foundation

/// Defines the persistent data representation of a user.
///
/// A user is uniquely identified by the composite key of (`userId`, `projectId`).
///
/// - warning: This object contains sensitive data.
/// Implementers must ensure secure storage (e.g., encryption at rest).
public final class UserDTO: NSObject, Sendable {
/// The identifier of the user, which is unique within the scope of a project. Could be email, username, etc.
public let userId: String

/// The identifier of the project this user belongs to.
public let projectId: String

/// The revocation status of the user.
public let revoked: Bool

/// The user's PIN's number of digits.
public let pinLength: Int

/// The identifier of this user registration in the MIRACL Trust Platform.
public let mpinId: Data

/// A secure user token.
///
/// - warning:
/// This field contain sensitive data. The storage implementation
/// is responsible for its secure handling, including encryption at rest.
public let token: Data

/// Data required for a server-side validation.
public let dtas: String

/// The public part of the user's signing key.
public let publicKey: Data?

public init(
userId: String,
projectId: String,
revoked: Bool,
pinLength: Int,
mpinId: Data,
token: Data,
dtas: String,
publicKey: Data?
) {
self.userId = userId
self.projectId = projectId
self.revoked = revoked
self.pinLength = pinLength
self.mpinId = mpinId
self.token = token
self.dtas = dtas
self.publicKey = publicKey
}
}

extension UserDTO {
func toUser() -> User {
User(
userId: userId,
projectId: projectId,
revoked: revoked,
pinLength: pinLength,
mpinId: mpinId,
token: token,
dtas: dtas,
publicKey: publicKey
)
}
}
10 changes: 5 additions & 5 deletions MIRACLTrust/MIRACLTrust-Sources/User Storage/UserStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ public protocol UserStorage: Sendable {

/// Adds a new user to the storage.
/// - Parameter user: a user that needs to be added to the storage.
func add(user: User) throws
func add(user: UserDTO) throws

/// Deletes the user from the storage.
/// - Parameter user: a user that needs to be deleted to the storage.
func delete(user: User) throws
func delete(user: UserDTO) throws

/// Updates the user in the storage
/// - Parameter user: a user that needs to be updated to the storage.
func update(user: User) throws
func update(user: UserDTO) throws

/// Get all users written in the storage.
func all() -> [User]
func all() -> [UserDTO]

/// Get User object by its user id and project id. If User isn't present in the storage this method returns nil.
/// - Parameters:
/// - userId: a user id to be checked in the storage.
/// - projectId: a project id to be checked in the storage.
func getUser(by userId: String, projectId: String) -> User?
func getUser(by userId: String, projectId: String) -> UserDTO?
}
Loading
Loading