WalletUtils

public class WalletUtils

A utility class with functions for handling universal links or login requests for wallets.

  • Create a short login code for manual verification of the login request by the user. The algorithm used by this function matches the one in the backend and will generate the same code for a particular login request.

    Declaration

    Swift

    public static func createLoginCode(nonce: String, callbackUrl: String) -> String

    Parameters

    nonce

    The unique nonce for this login request, as received from the notification or pending request.

    callbackUrl

    The callbackUrl for this login request, as received from the notification or pending request.

    Return Value

    The 6-character login code for display to the user.

  • Create the cryptographic signature for the document digest using the default registered credential.

    Declaration

    Swift

    public static func createDocumentSignature(digest: String) -> String

    Parameters

    digest

    The document’s digest.

    Return Value

    The base64-encoded signature, calculated using the default registered credential.

  • Assemble the URL components for the login request callback using the default registered credential.

    static func onReject() { if loginInfo != nil { let url = WalletUtils.buildLoginCallback(loginInfo: loginInfo, result: false) UIApplication.shared.openURL(url) } }

    Declaration

    Swift

    public static func buildLoginCallback(_ loginInfo: SignatureRequest, amr: AuthMethod?) -> URL

    Parameters

    loginInfo

    The SignatureRequest object, as received from the notification or pending request.

    amr

    The Authentication Method Reference value how the user was authenticated, or nil

    Return Value

    The final callback URL, with all required query parameters.

  • Assemble the URL components for the denial request callback using the default registered credential.

    Declaration

    Swift

    public static func buildDenyCallback(_ loginInfo: SignatureRequest) -> URL

    Parameters

    loginInfo

    The SignatureRequest object, as received from the notification or pending request.

    Return Value

    The final callback URL, with all required query parameters.

  • Assemble the URL components for the claim request callback using the default registered credential.

    Declaration

    Swift

    public static func buildClaimCallback(_ loginInfo: SignatureRequest, amr: AuthMethod?, claims: [String]?, issuers: [String]?) -> URL

    Parameters

    loginInfo

    The SignatureRequest object, as received from the notification or pending request.

    amr

    The Authentication Method Reference value how the user was authenticated, or nil

    claims

    An array with the Base64 encoded claims

    issuer

    An array with the Base64 encoded claims of the claim issuer(s).

    Return Value

    The final callback URL, with all required query parameters.

  • Invoke an universal Link or open a webpage.

    Declaration

    Swift

    public static func invokeSystemCallback(url: URL, onSuccess: HttpUtils.SuccessCallback? = nil, onSuccessWithHeaders: HttpUtils.SuccessCallbackWithHeaders? = nil, onError: @escaping (String) -> Void)

    Parameters

    url

    The URL here is the universal link to invoke or webpage to open.

    onSuccess

    Success callback, invoked on the main (UI) thread. Either one of onSuccess or onSuccessWithHeaders must be provided.

    onSuccessWithHeaders

    Success callback with headers included, invoked on the main (UI) thread. Either one of onSuccess or onSuccessWithHeaders must be provided.

    onError

    Failure callback, invoked on the main (UI) thread with error message.

    Return Value

  • Undocumented

    Declaration

    Swift

    public static func invokeClaimCallback(_ loginInfo: SignatureRequest
        , amr: AuthMethod?
        , claims: [String]?
        , issuers: [String]?
        , onSuccess: HttpUtils.SuccessCallback? = nil
        , onSuccessWithHeaders: HttpUtils.SuccessCallbackWithHeaders? = nil
        , onError: @escaping (String) -> Void) -> URL
  • Assemble the URL components for the claim request callback using the default registered credential and execute a HTTP request.

    Declaration

    Swift

    public static func invokeClaimCallback(_ loginInfo: SignatureRequest
        , amr: AuthMethod?
        , claims: [Claim]
        , onSuccess: HttpUtils.SuccessCallback? = nil
        , onSuccessWithHeaders: HttpUtils.SuccessCallbackWithHeaders? = nil
        , onError: @escaping (String) -> Void) -> URL

    Parameters

    loginInfo

    The SignatureRequest object, as received from the notification or pending request.

    amr

    The Authentication Method Reference value how the user was authenticated, or nil

    claims

    Array of accepted Claim objects

    onSuccess

    Success callback, invoked on the main (UI) thread with parsed JSON body. Either one of onSuccess or onSuccessWithHeaders must be provided.

    onSuccessWithHeaders

    Success callback with parsed JSON body and headers included, invoked on the main (UI) thread. Either one of onSuccess or onSuccessWithHeaders must be provided.

    onError

    Failure callback, invoked on the main (UI) thread with error message.

    Return Value

    The URL that was invoked

  • Assemble the URL components for the login request callback using the default registered credential and execute a HTTP request.

    viewController.rejectCallback = { _ in
       WalletUtils.invokeLoginCallback(loginInfo: loginInfo, result: false, onSuccess: { _ in }, onError: {_ in })
       gotoNextViewController()
    }
    

    Declaration

    Swift

    public static func invokeDenyCallback(_ loginInfo: SignatureRequest
        , onSuccess: HttpUtils.SuccessCallback? = nil
        , onSuccessWithHeaders: HttpUtils.SuccessCallbackWithHeaders? = nil
        , onError: @escaping (String) -> Void) -> URL

    Parameters

    loginInfo

    The SignatureRequest object, as received from the notification or pending request.

    onSuccess

    Success callback, invoked on the main (UI) thread with parsed JSON body. Either one of onSuccess or onSuccessWithHeaders must be provided.

    onSuccessWithHeaders

    Success callback with parsed JSON body and headers included, invoked on the main (UI) thread. Either one of onSuccess or onSuccessWithHeaders must be provided.

    onError

    Failure callback, invoked on the main (UI) thread with error message.

    Return Value

    The URL that was invoked

  • Assemble the URL components for the login request callback using the default registered credential and execute a HTTP request.

    viewController.rejectCallback = { _ in
        WalletUtils.invokeLoginCallback(loginInfo: loginInfo, result: false, onSuccess: { _ in }, onError: {_ in })
        gotoNextViewController()
    }
    

    Declaration

    Swift

    public static func invokeLoginCallback(_ loginInfo: SignatureRequest
        , amr: AuthMethod?
        , onSuccess: HttpUtils.SuccessCallback? = nil
        , onSuccessWithHeaders: HttpUtils.SuccessCallbackWithHeaders? = nil
        , onError: @escaping (String) -> Void) -> URL

    Parameters

    loginInfo

    The SignatureRequest object, as received from the notification or pending request.

    amr

    The Authentication Method Reference value how the user was authenticated, or nil

    onSuccess

    Success callback, invoked on the main (UI) thread with parsed JSON body. Either one of onSuccess or onSuccessWithHeaders must be provided.

    onSuccessWithHeaders

    Success callback with parsed JSON body and headers included, invoked on the main (UI) thread. Either one of onSuccess or onSuccessWithHeaders must be provided.

    onError

    Failure callback, invoked on the main (UI) thread with error message.

    Return Value

    The URL that was invoked

  • Enum that specifies how to invoke the callback URL.

    See more

    Declaration

    Swift

    public enum CallbackType : String
  • Enum to identify from where the request to confirm/deny originated.

    See more

    Declaration

    Swift

    public enum RequestSource
  • Enum to specify the type of request in TK Wallet.

    See more

    Declaration

    Swift

    public enum RequestType
  • Enum to specify the request action taken by the user.

    See more

    Declaration

    Swift

    public enum RequestResult : String
  • A class with all fields related to a particular login request.

    See more

    Declaration

    Swift

    public class SignatureRequest
  • Parse the universal link for this login request.

    Declaration

    Swift

    public static func parseLoginUniversalLink(url: URL) -> SignatureRequest?

    Parameters

    url

    The universal link that was received by the wallet application.

    Return Value

    A new SignatureRequest object with all fields related to a particular login request, or nil if the link was not a suitable universal link.

  • Parse the notification payload for this login request.

    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo:[AnyHashable: Any], fetchCompletionHandler:@escaping (UIBackgroundFetchResult) -> Void) { let loginInfo = WalletUtils.parseLoginNotification(userInfo: userInfo as NSDictionary) //… }

    Declaration

    Swift

    public static func parseLoginNotification(userInfo: NSDictionary) -> SignatureRequest?

    Parameters

    url

    The userInfo dictionary, as received from didReceiveRemoteNotification.

    Return Value

    A new SignatureRequest object with all fields related to a particular login request.

  • Parse a login request obtained from getPendingRequest API.

    Declaration

    Swift

    public static func parseLoginRequest(userInfo: NSDictionary) -> SignatureRequest?

    Parameters

    url

    The userInfo dictionary, as received from getPendingRequest API.

    Return Value

    A new SignatureRequest object with all fields related to a particular login request.