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.1.0"
s.version = "1.2.0"
s.license = { :type => "Apache2", :file => "LICENSE" }
s.author = { "MIRACL" => "[email protected]" }
s.homepage = "https://github.com/miracl/trust-sdk-ios"
Expand Down
29 changes: 19 additions & 10 deletions MIRACLTrust/MIRACLTrust-Sources/Authentication/Authenticator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -272,15 +272,22 @@ struct Authenticator: Sendable, AuthenticatorBlueprint {
authenticateResponse: AuthenticateResponse,
pinCode: String
) {
let registrator = Registrator(
userId: user.userId,
api: miraclAPI,
userStorage: userStorage,
projectId: user.projectId,
crypto: crypto,
didRequestPinHandler: { processPinHandler in
guard let token = renewSecretResponse.token else {
finishAuthentication(with: authenticateResponse)
return
}

do {
let registrator = try Registrator(
userId: user.userId,
activationToken: token,
api: miraclAPI,
userStorage: userStorage,
projectId: user.projectId,
crypto: crypto
) { processPinHandler in
processPinHandler(pinCode)
}, completionHandler: { updatedUser, error in
} completionHandler: { updatedUser, error in
if let updatedUser = updatedUser {
logOperation(operation: LoggingConstants.wamFinished)
redoAuthentication(with: updatedUser, pinCode: pinCode)
Expand All @@ -291,9 +298,11 @@ struct Authenticator: Sendable, AuthenticatorBlueprint {
finishAuthentication(with: authenticateResponse)
}
}
)

registrator.getWAMSecret(dvsRegistrationToken: renewSecretResponse.token ?? "")
registrator.register()
} catch {
finishAuthentication(with: authenticateResponse)
}
}

private func finishAuthentication(with response: AuthenticateResponse) {
Expand Down
10 changes: 5 additions & 5 deletions MIRACLTrust/MIRACLTrust-Sources/Crypto/Crypto.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,11 @@ struct Crypto: CryptoBlueprint, Sendable {
return (tokenData, nil)
}

public func sign(message: Data,
signingMpinId: Data,
signingToken: Data,
pinCode: Int32,
timestamp: Int32) -> (Data, Data, CryptoError?) {
func sign(message: Data,
signingMpinId: Data,
signingToken: Data,
pinCode: Int32,
timestamp: Int32) -> (Data, Data, CryptoError?) {
logOperationStarted()

let rng = randomNumberGenerator()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,6 @@ enum LoggingConstants {
static let updatingCodeStatus = "Updating codeStatus."
static let authenticateError = "Error in authenticate request: "
static let quickCodeVerificationStarted = "Start quick code verification"
static let registrationInvalidClientSecretShareURL = "Invalid client secret share URL"
static let registrationGettingClientSecretShares = "Getting Client secret shares operation started"
}
101 changes: 16 additions & 85 deletions MIRACLTrust/MIRACLTrust-Sources/Networking/API.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,59 +28,28 @@ struct API: Sendable, APIBlueprint {
clientSettings = APISettings(platformURL: baseURL)
}

/// Registering user
/// - Parameters:
/// - userId: id
/// - deviceName: device name
/// - activationToken: code
/// - completionHandler: handler
/// - Tag: API-_FUNC_registeruserfordevicenameactivationtokencompletionhandler
func registerUser(
for userId: String,
deviceName: String,
userId: String,
activationToken: String,
deviceName: String,
publicKey: String,
pushToken: String?,
completionHandler: @escaping APIRequestCompletionHandler<RegistrationResponse>
) {
let requestBody = RegistrationRequestBody()
requestBody.activateCode = activationToken
requestBody.deviceName = deviceName
requestBody.userId = userId
requestBody.pushToken = pushToken
let registrationRequestBody = RegistrationRequestBody(
userId: userId,
deviceName: deviceName,
activationToken: activationToken,
publicKey: publicKey,
pushToken: pushToken
)

do {
let request = try APIRequest(
url: clientSettings.registerURL,
url: clientSettings.registrationURL,
path: nil,
method: .put,
requestBody: requestBody,
logger: logger
)

executor.execute(apiRequest: request, completion: completionHandler)
} catch {
completionHandler(.failed, nil, error)
}
}

/// Creates signature.
/// - Parameters:
/// - mpinId: mpinid
/// - regOTT: regott
/// - completionHandler: completion handler
/// - Tag: API-_FUNC_signatureforregottcompletionhandler
func signature(
for mpinId: String,
regOTT: String,
publicKey: String,
completionHandler: @escaping APIRequestCompletionHandler<SignatureResponse>
) {
do {
let request = try APIRequest(
url: clientSettings.signatureURL,
path: "/\(mpinId)",
queryParameters: ["regOTT": regOTT, "publicKey": publicKey],
requestBody: EmptyRequestBody(),
method: .post,
requestBody: registrationRequestBody,
logger: logger
)

Expand All @@ -90,18 +59,13 @@ struct API: Sendable, APIBlueprint {
}
}

/// Getting second client secret share
/// - Parameters:
/// - cs2URL: url
/// - completionHandler: completion handler
/// - Tag: API-_FUNC_getclientsecret2forcompletionhandler
func getClientSecret2(
for cs2URL: URL,
func getClientSecretShare(
_ clientSecretShareURL: URL,
completionHandler: @escaping APIRequestCompletionHandler<ClientSecretResponse>
) {
do {
let request = try APIRequest(
url: cs2URL,
url: clientSecretShareURL,
path: nil,
requestBody: EmptyRequestBody(),
logger: logger
Expand Down Expand Up @@ -216,39 +180,6 @@ struct API: Sendable, APIBlueprint {
}
}

/// Get client secret 1 for signing
/// - Parameters:
/// - publicKey: public key
/// - signingRegistrationToken: token
/// - deviceName: device identifier into the portal application.
/// - completionHandler: completion handler
/// - Tag: API-_FUNC_signingclientsecret1publickeysigningregistrationtokendevicenamecompletionhandler
func signingClientSecret1(
publicKey: String,
signingRegistrationToken: String,
deviceName: String,
completionHandler: @escaping APIRequestCompletionHandler<SigningClientSecret1Response>
) {
let requestBody = SigningClientSecret1RequestBody()
requestBody.dvsRegisterToken = signingRegistrationToken
requestBody.publicKey = publicKey
requestBody.deviceName = deviceName

do {
let request = try APIRequest(
url: clientSettings.dvsRegURL,
path: nil,
method: .post,
requestBody: requestBody,
logger: logger
)

executor.execute(apiRequest: request, completion: completionHandler)
} catch {
completionHandler(.failed, nil, error)
}
}

/// Sending request for verifying user identity.
/// - Parameters:
/// - projectId: id of the project
Expand Down
23 changes: 5 additions & 18 deletions MIRACLTrust/MIRACLTrust-Sources/Networking/APIBlueprint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,16 @@ import Foundation

protocol APIBlueprint: Sendable {
func registerUser(
for userId: String,
deviceName: String,
userId: String,
activationToken: String,
deviceName: String,
publicKey: String,
pushToken: String?,
completionHandler: @escaping APIRequestCompletionHandler<RegistrationResponse>
)

func signature(
for mpinId: String,
regOTT: String,
publicKey: String,
completionHandler: @escaping APIRequestCompletionHandler<SignatureResponse>
)

func getClientSecret2(
for cs2URL: URL,
func getClientSecretShare(
_ clientSecretShareURL: URL,
completionHandler: @escaping APIRequestCompletionHandler<ClientSecretResponse>
)

Expand All @@ -42,13 +36,6 @@ protocol APIBlueprint: Sendable {
completionHandler: @escaping APIRequestCompletionHandler<AuthenticateResponse>
)

func signingClientSecret1(
publicKey: String,
signingRegistrationToken: String,
deviceName: String,
completionHandler: @escaping APIRequestCompletionHandler<SigningClientSecret1Response>
)

func verifyUser(
projectId: String,
userId: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
struct APIErrorResponse: Codable {
public var error: String
public var info: String
public var context: [String: String]?
var error: String
var info: String
var context: [String: String]?
}
8 changes: 2 additions & 6 deletions MIRACLTrust/MIRACLTrust-Sources/Networking/APISettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ import Foundation

/// URLs used to make a call to given MIRACL endpoints. This class is initialised when the [API] class instance is created from the response taken from the client settings.
struct APISettings: Sendable {
let signatureURL: URL
let registerURL: URL
let registrationURL: URL
let authenticateURL: URL
let pass1URL: URL
let pass2URL: URL
let dvsRegURL: URL
let verificationURL: URL
let verificationConfirmationURL: URL
let codeStatusURL: URL
Expand All @@ -16,12 +14,10 @@ struct APISettings: Sendable {
let verificationQuickCodeURL: URL

init(platformURL: URL) {
signatureURL = APISettings.createAPISettingsURL(platformURL: platformURL, path: "/rps/v2/signature")!
registerURL = APISettings.createAPISettingsURL(platformURL: platformURL, path: "/rps/v2/user")!
registrationURL = APISettings.createAPISettingsURL(platformURL: platformURL, path: "/registration")!
authenticateURL = APISettings.createAPISettingsURL(platformURL: platformURL, path: "/rps/v2/authenticate")!
pass1URL = APISettings.createAPISettingsURL(platformURL: platformURL, path: "/rps/v2/pass1")!
pass2URL = APISettings.createAPISettingsURL(platformURL: platformURL, path: "/rps/v2/pass2")!
dvsRegURL = APISettings.createAPISettingsURL(platformURL: platformURL, path: "/rps/v2/dvsregister")!
verificationURL = APISettings.createAPISettingsURL(platformURL: platformURL, path: "/verification/email")!
verificationConfirmationURL = APISettings.createAPISettingsURL(platformURL: platformURL, path: "/verification/confirmation")!
codeStatusURL = APISettings.createAPISettingsURL(platformURL: platformURL, path: "/rps/v2/codeStatus")!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ struct FallbackRequestErrorResponse: Codable {
}

struct FallbackErrorResponse: Codable {
public var code: String
public var info: String
public var context: [String: String]?
var code: String
var info: String
var context: [String: String]?
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class RegistrationRequestBody: Codable {
var userId: String = ""
var deviceName: String = ""
var activateCode: String = ""
struct RegistrationRequestBody: Codable {
var userId: String
var deviceName: String
var activationToken: String
var publicKey: String
var pushToken: String?
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import Foundation

struct RegistrationResponse: Codable {
var mpinId: String
var regOTT: String
var projectId: String
var dtas: String
var curve: String
var secretUrls: [String]
}
Loading
Loading