Initialization

Before using the SDK, please provide the OIDC JWT verifier to OpenWeb3 so that we can register your application,you need to perform the initialization setup. Follow these steps to initialize the SDK:

Auth

import OpenWeb3Lib

private var openPlatformPlugin: OpenPlatformPlugin = PluginsManager.getInstance().getPlugin(PluginName.openPlatform.rawValue)!
    
let idToken = "eyJhbGciOiJSUzI1NiIsImtpZCI6IjM5ZTg2YmMxYjBjMjI5NDBkNDRjZjNmNWI4NWZmZWYwYTZjNmQzNzIiLCJ0eXAiOiJKV1QifQ.eyJ1aWQiOiJtdHNvY2lhbEBnbWFpLmNvbSIsImlzcyI6ImZpcmViYXNlLWFkbWluc2RrLTR2ejMwQG10c29jaWFsLmlhbS5nc2VydmljZWFjY291bnQuY29tIiwiZXhwIjoxNzUxODEzMTUxLCJpYXQiOjE3MjA3MDkxNTEsImF1ZCI6Imh0dHBzOi8vaWRlbnRpdHl0b29sa2l0Lmdvb2dsZWFwaXMuY29tL2dvb2dsZS5pZGVudGl0eS5pZGVudGl0eXRvb2xraXQudjEuSWRlbnRpdHlUb29sa2l0Iiwic3ViIjoiZmlyZWJhc2UtYWRtaW5zZGstNHZ6MzBAbXRzb2NpYWwuaWFtLmdzZXJ2aWNlYWNjb3VudC5jb20ifQ.IxKdRdKZhbiYIbRd7nzieti--cEHNA-65rg01Wl6h64cXVviPlZ5MsaueN4uRUODtYs6mdYMAteoy54Wi0GMJzIGMkClUJtbWTOfW1L43YdB4R4XhhVsx2gvF8iCF0MQrDB8ekfyWEqbBdJdbM0BUH0NjSl1Mg15Ta-Rx1cYsk41vmDULpkqHJl93Xjuu2ts1KY7Rs3kNp1NAj9-gC4kHzUG57dmvLqteb4qMmUN7h2tq_np3rdGUBRzxB_YBOnqICAmJ-u6knV_XT08Ep1fB-H_HqR41W_FMgv3EW-V5pApDddJttNjaTy8rJfy2xL9mOhQV0OH-1vHjm4Mz2Jpeg"

private func tokenProvider() async -> String? {
        return await withCheckedContinuation { [weak self] continuation in
            continuation.resume(returning:idToken)
        }
}

openPlatformPlugin.signIn(
            verifier: "123",
            idTokenProvider: tokenProvider,
            onVerifierSuccess: { [weak self] in
                // Do something
            },
            onVerifierFailure: { code, message in
                print("Verifier Err, code= \(code), message: \(String(describing: message))")
            })

In the above code, we use PluginsManager.getInstance().getPlugin(PluginName.openPlatform.rawValue) to obtain the singleton instance of the OpenPlatformPlugin and call the auth method for initialization. You need to provide the following parameters:

  • verifier: JWT verifier
  • tokenProvider: JWT token provider .
  • onVerifierSuccess: Triggered when the installation succeeds
  • onVerifierFailure: Triggered when the installation fails

Setup MiniAppService

import OpenWeb3Lib

private lazy var miniAppService: MiniAppService = openPlatformPlugin.getMiniAppService()!

    let appConfig = AppConfig.Builder(appName: "YouAppName",
                                              webAppName: "OpenWeb3",
                                              mePath: ["https://openweb3.io","https://t.me"],
                                              window: window,
                                              appDelegate: MiniSDKManager.shared)
                .languageCode("en")
                .userInterfaceStyle(.light)
                .maxCachePage(5)
                .resourceProvider(nil)
                .floatWindowSize(width: 90.0, height: 159.0)
                .build()
            
           miniAppService.setup(config: appConfig)

In the above code, we use openPlatformPlugin.getMiniAppService()! to obtain the singleton instance of the MiniAppService and call the setup method for initialization. You need to provide the following parameters:

  • window: The application's UIWindow.
  • appName: Your application name.
  • webAppName : Your web-app name
  • mePath: The list of mini program hosts.
  • languageCode: Language code (optional, default: "en").
  • userInterfaceStyle: User Interface Style(optional, default: .light).
  • maxCachePage: The maximum number of cached mini-app.(optional, default: 5).
  • resourcesProvider: Instance of a custom resources provider (optional).
  • appDelegate: Instance of a custom application delegate (optional).