Introduction

Introduction

MetaKeep mobile is a lightweight SDK that can be used in any Android, iOS, React Native, or any other mobile platform. Note that for any platform not listed here, you can write a minimal amount of code to wrap the native SDKs and expose the required functionality.

Importing the library

Follow the instructions below for your platform to import the library.

Initializing the library

Now that you've imported MetaKeep Mobile SDK, you need to first initialize the SDK with the appId. You can find appId in the developer console. Here are examples-

import xyz.metakeep.sdk.*

// Init SDK
// Replace with your own App id.
val sdk = MetaKeep(appId = "<app_id>", AppContext(activity!!))
import MetaKeep

// Init SDK
// Replace with your own App id.
// Note the empty AppContext class. It's reserved for future use.
let sdk = MetaKeep(appId: "<app_id>", appContext: AppContext())
import MetaKeep from 'metakeep-react-native-sdk';

// Init SDK
// Replace with your own App id.
const sdk = new MetaKeep( "<app_id>");
import 'package:metakeep_flutter_sdk/metakeep_flutter_sdk.dart';

// Init SDK
// Replace with your own App id.
const sdk = new MetaKeep( "<app_id>");

❗️

SDK can only be initialized inside an Activity or Fragment on Android.

Make sure to initialize the SDK inside your Activity or Fragment. Otherwise, the activity will be null causing your app to crash.

If you already have a signed-in user, you can provide the user's email address to the MetaKeep SDK. This provides a native logged-in user experience when your app and MetaKeep SDK are interacting. If the user's email is not provided, the SDK will ask the user for their email address when you perform the first SDK operation.

sdk.user = User(email = "[email protected]")
sdk.user = User(email: "[email protected]")
await sdk.setUser({
    email: '[email protected]',
  });
await sdk.setUser({
    "email": "[email protected]",
  });

SDK Operation Response

On iOS and Android, all SDK operations take a Callback object as a parameter. The Callback object expects 2 functions as parameters: onSuccess and onFailure. The onSuccess function is called when the operation is successful. The onFailure function is called when the operation fails.

On React Native, all SDK operations are asynchronous and return a Promise object. The Promise object can be used to get the result of the operation.

On Flutter, all SDK operations return a Future object. The Future object can be used to get the result of the operation. The result is a dynamic object that contains parsed JSON data.

val callback =
    Callback(
  			// Called on operation success
        onSuccess = { response: JsonResponse -> Log.d("Success", response.toString()) },
  			// Called on operation failure
        onFailure = { error: JsonResponse -> Log.d("Error", error.toString()) },
    )
let callback = Callback(
  // Called on operation success
  onSuccess: { (result: JsonResponse) in
    print("onSuccess")
    print(result.description)
  },
  // Called on operation failure
  onFailure: { (error: JsonResponse) in
    print("onFailure")
    print(error.description)
  }
)

Both functions are called with a result object of type JsonResponse as a parameter. The JsonResponse object is a wrapper around the JSON response returned by the MetaKeep API. The response will always contain a status field which is a string indicating the status of the operation. Here's how to read data from the response:

val callback =
    Callback(
        onSuccess = { response: JsonResponse ->
            run {
                // Status field
                val status: String? = response.data["status"]?.jsonPrimitive?.content

                // Signature field
                val signature: String? = response.data["signature"]?.jsonPrimitive?.content

                // Signature r value
                val r: String? = response.data["r"]?.jsonPrimitive?.content

                // Signature s value
                val s: String? = response.data["s"]?.jsonPrimitive?.content

                // Signature v value
                val v: String? = response.data["v"]?.jsonPrimitive?.content

                Log.d("OnSuccess", "status: $status")
                Log.d("OnSuccess", "signature: $signature")
                Log.d("OnSuccess", "r: $r")
                Log.d("OnSuccess", "s: $s")
                Log.d("OnSuccess", "v: $v")
            }
        },
        onFailure = { error: JsonResponse -> Log.d("Error", error.toString()) },
    )
let callback = Callback(
  onSuccess: { (result: JsonResponse) in
    print("onSuccess")

    // Status field
    let status = result.data["status"] as? String

    // Signature field
    let signature = result.data["signature"] as? String

    // Signature r field
    let r = result.data["r"] as? String

    // Signature s field
    let s = result.data["s"] as? String

    // Signature v field
    let v = result.data["v"] as? String

    print("status: \(status ?? "UNKNOWN")")
    print("signature: \(signature ?? "UNKNOWN")")
    print("r: \(r ?? "UNKNOWN")")
    print("s: \(s ?? "UNKNOWN")")
    print("v: \(v ?? "UNKNOWN")")

  },
  onFailure: { (error: JsonResponse) in
    print("onFailure")
    print(error.description)
  }
)

Configuration options

The following properties can be configured in the MetaKeep SDK:

OptionDescriptionRequired
appIdThis is your public app ID that you get from the MetaKeep Developer Console. Use this to customize the look and feel of the MetaKeep wallet UI for your users.Yes
userUse this to provide the email address of the signed-in user to create a seamless UI experience.

If not specified, users will be asked for their identity.
No

© Copyright 2024, Passbird Research Inc.