Skip to main content

Initializing Web3auth CoreKit tKey iOS SDK

Once you have installed the Web3Auth Core Kit tKey SDK, the next step is to initialize it. This involves a few steps, such as initiating the tKey SDK with the service provider and modules.

Configuring Service Provider

Service Provider in tKey generates a Share A, i.e., the private key share managed by a wallet service provider via their authentication flows. This share in our wallet infrastructure refers to the social login aspect, where we associate a private key share with the user's social login, enabling the seamless login experience.

To configure your service provider, you must use CustomAuth Swift SDK. Please note that this SDK is not automatically installed with tKey iOS SDK, so you must install it first.

Usage of CustomAuth Swift SDK

Installation

Swift Package Manager

Add the CustomAuth Swift SDK to your project
  1. In Xcode, with your app project open, navigate to File > Add Packages.

  2. When prompted, add the CustomAuth Swift SDK repository:

    https://github.com/torusresearch/customauth-swift-sdk

    From the Dependency Rule dropdown, select Exact Version and enter 6.0.1 as the version.

  3. When finished, Xcode will automatically begin resolving and downloading your dependencies in the background.

Cocoapods

pod 'CustomAuth', '~> 6.0.1'

Initialization

Initalize the SDK depending on the login you require.

import CustomAuth

let sub = SubVerifierDetails(
loginType: .web, // default .web
loginProvider: <typeOfLogin>, // .google,
clientId: "<your-client-id>",
verifierName: "<verifier-name>",
redirectURL: "<your-redirect-url>",
browserRedirectURL: "<your-browser-redirect-url>")

let tdsdk = CustomAuth(
aggregateVerifierType: "<type-of-verifier>", // singleLogin, singleIdVerifier supported
aggregateVerifierName: "<verifier-name>", // Web3Auth Custom verifier name
subVerifierDetails: [sub],
network: .TESTNET)

SubVerifierDetails

ParameterTypeMandatoryDescription
loginTypeSubVerifierTypeNologinType to be used. [ web: default, installed]
loginProviderLoginProvidersYesloginProvider to be used. [ google, facebook, twitch, reddit, discord, apple, github, linkedin, kakao, twitter, weibo, line, wechat, email_password, and jwt ]
clientIdStringYeslogin provider's client Id.
verifierStringYesWeb3Auth verifier name
redirectURLStringYesIt refers to a url for the login flow to redirect into your app, it should have a scheme that is registered by your app, for example com.mycompany.myapp://redirect
browserRedirectURLStringNoIt refers to a page that the browser should use in the login flow, it should have a http or https scheme. e.g. https://scripts.toruswallet.io/redirect.html
jwtParamsStringNoAdditional JWT parameters to be passed.
urlSessionURLSessionNoCustom URLSession to be used.

CustomAuth

ParameterTypeMandatoryDescription
aggregateVerifierTypeStringYesType of the aggregate verifier.
aggregateVerifierStringYesName of the aggregate verifier.
subVerifierDetails[SubVerifierDetails]YesArray of SubVerifierDetails.
networkNetworkYesNetwork to be used. [ MAINNET, TESTNET, CYAN, AQUA]

Initializing Service Provider

  1. triggerLogin() returns a promise that resolve with a Dictionary that contain at least privateKey and publicAddress field.
  2. Initialize the service provider with the privateKey retrived by the result of triggerLogin().
tdsdk.triggerLogin(controller: <UIViewController>?, browserType: <method-of-opening-browser>, modalPresentationStyle: <style-of-modal>).done{ data in
print("private key rebuild", data)
let key = data["privateKey"]
service_provider = try! ServiceProvider(enable_logging: true, postbox_key: key)
}.catch{ err in
print(err)
}

Instantiating tKey

let thresholdKey = try? ThresholdKey(
storage_layer: storage_layer,
service_provider: service_provider,
enable_logging: true,
manual_sync: false)

Parameters

ParameterTypeDescriptionMandatory
metadataMetadataMetadata object containing the metadata details of tKey.No
sharesShareStorePolyIdIndexMapArray of ShareStore with PolyId.No
storage_layerStorageLayerTakes in the Storage Provider InstanceNo
service_providerServiceProviderTakes in the Service Provider InstanceNo
local_matadata_transitionsMetadataLocal metadata transitionsNo
enable_loggingBoolThis option is used to specify whether to enable logging or not.No
manual_syncBoolmanual sync provides atomicity to your tkey share. If manual_sync is true, you should sync your local metadata transitions manually to your storage_layer, which means your storage layer doesn’t know the local changes of your tkey unless you manually sync, gives atomicity. Otherwise, If manual_sync is false, then your local metadata changes will be synced automatically to your storage layer. If manual_sync = true and want to synchronize manually, you need to call sync_local_metadata_transitions() manually.No

Example

guard let postboxkey = userData["privateKey"] as? String else {
alertContent = "Failed to get postboxkey"
return
}

guard let storage_layer = try? StorageLayer(enable_logging: true, host_url: "https://metadata.tor.us", server_time_offset: 2) else {
alertContent = "Failed to create storage layer"
return
}

guard let service_provider = try? ServiceProvider(enable_logging: true, postbox_key: postboxkey) else {
alertContent = "Failed to create service provider"
return
}

guard let thresholdKey = try? ThresholdKey(
storage_layer: storage_layer,
service_provider: service_provider,
enable_logging: true,
manual_sync: false) else {
alertContent = "Failed to create threshold key"
return
}

threshold_key = thresholdKey