1. Installation
  2. Install Motor Flutter

The Motor SDK is a set of developer tools for building decentralized applications on the Sonr network. It currently supports Flutter (iOS, Android, MacOS) with plans to support Javascript, React Native, and Web in the future.

Motor Flutter is a Flutter library designed to help developers utilize Sonr in their apps. You can find the package at motor.build.

Using Motor SDK

The Motor Flutter SDK uses the GetX package to manage state. This means that you must wrap the MotorFlutter service into the Get.putAsync method. For more information on this, please refer to their documentation.

Start the Motor Node

Spawning a new Motor instance is the first step in using the SDK. This is where you’ll configure your app’s connection to the Sonr network.

There should exist only one instance of Motor throughout the lifetime of your application.

import (
    "github.com/sonr-hq/sonr/pkg/motor"
    "github.com/sonr-hq/sonr/third_party/types/common"
)

func main() {
    mtr, err := EmptyMotor(&mt.InitializeRequest{
		    DeviceId: "unique_device_id", // this field must be unique to the device
	  }, common.DefaultCallback())
}

Before you can use the motor methods, you must finish initialization by either creating an account or logging in. To create an account you must have the following information.

ParameterDescription
deviceIdA unique manufacturer identifier used to recognize the device a Motor is running on
passwordA user defined secure password to be used in the instance of account recovery
dscDevice Specific Credential. A 32-byte AES key used to represent the device. Keep this stored in the device’s keychain.
mtr, err := EmptyMotor(&mt.InitializeRequest{
    DeviceId: "unique_device_id", // this field must be unique to the device
}, common.DefaultCallback())
if err != nil {
  panic(err)
}

createResponse, err := mtr.CreateAccount(mt.CreateAccountRequest{
		Password:  "password123",
		AesDscKey: aesKey,
})

// store the pre-shared key somewhere
store(createResponse.AesPskKey)

Logging in uses a combination of the below.

ParameterDescription
didThe DID generated during account creation
dscKeyDevice Specific Credential. A 32-byte AES key used to represent the device. Keep this stored in the device’s keychain.
pskKeyPre-shared key. A 32-byte AES key. This key is meant to be shared between all devices
passwordThe password used during account creation

To login you must provide the PSK and one of either the password or DSC.

mtr, err := EmptyMotor(&mt.InitializeRequest{
    DeviceId: "unique_device_id",
}, common.DefaultCallback())
if err != nil {
  panic(err)
}

loginResponse, err := mtr.Login(mt.LoginRequest{
    Did:       "<address of the account to be logged in>",
    Password:  "password123",
    AesPskKey: pskKey,
})

// -- OR --

loginResponse, err := mtr.Login(mt.LoginRequest{
    Did:       "<address of the account to be logged in>",
    AesDscKey: dscKey,
    AesPskKey: pskKey,
})