Swift implementation of Xiaomi's BLE authentication

Last update: Jul 27, 2022

MiAuth

Xiaomi M365/Mi Authentication library written in Swift.

Features

  • M365 Authentication
  • Mi Authentication (WIP - Login doesn't work reliably yet)
  • Ninebot Authentication

Installation

Swift Package Manager

MiAuth currently only supports Swift Package Manager.

dependencies: [
    .package(url: "https://github.com/nouun/MiAuth.git", .upToNextMajor(from: "0.1.0"))
]

Example

MiClient

Below is a small example using MiClient to connect to a scooter named "MIScooter4565", register, print the token, and then get the serial number.

class MiClientTest {
    let client: MiClient

    init() {
        self.client = MiClient()
        self.client.delegate = self
    }
}

extension MiClientTest: MiDeviceDelegate {
    func didDiscover(device: CBPeripheral) {
        if device.name == "MIScooter4565" {
            self.client.connect(to: device)
        }
    }

    func didRecieve(value: MiValue) {
        switch value {
        case .serial(number: let serial): print("Serial Number: " + serial)
        default: return
        }
    }

    func didUpdate(miState: MiState) {
        switch miState {
        case .authenticationReady:
            self.client.register()
        case .waitingForButtonPress:
            print("Press power button within 5 seconds")
        case .registered(token: let token):
            let tokenHex = toxen
                .map { String(format: "%02hhX", $0) }
                .joined(separator: " ")
            print("Token: \(tokenHex)")

            client.login(withToken: token)
        case .authenticated:
            self.client.write(payload: MiPayload.escSerialNumber)
        default: return
        }
    }
}

M365Client

Below is a small example using M365Client to connect to a scooter named "MIScooter4565", authenticate, and then get the serial number.

class M365ClientTest {
    let client: M365Client

    init() {
        self.client = M365Client()
        self.client.delegate = self
    }
}

extension M365ClientTest: MiDeviceDelegate {
    func didDiscover(device: CBPeripheral) {
        if device.name == "MIScooter4565" {
            self.client.connect(to: device)
        }
    }

    func didRecieve(value: MiValue) {
        switch value {
        case .serial(number: let serial): print("Serial Number: " + serial)
        default: return
        }
    }

    func didUpdate(miState: MiState) {
        switch miState {
        case .authenticated:
            self.client.write(payload: MiPayload.escSerialNumber)
        default: return
        }
    }
}

Support

For any support regarding MiAuth feel free to contact me on Discord at nouun#0246.

Credits

This would not have been possible without help from dnandra and his MiAuth documentation.

Also VPCCMCrypt for AES/CCM encryption implementation in Objective-C which is what AESCCM.swift is based on.

GitHub

https://github.com/nouun/miauth
You might also like...

The official Swift Library for Vital API, HealthKit and Devices

vital-ios The official Swift Library for Vital API, HealthKit and Devices Install We currently support SPM. Documentation Please refer to the official

Jul 28, 2022

BluetoothKit Easily communicate between iOS devices using BLE.

BluetoothKit Easily communicate between iOS devices using BLE. Background Apple mostly did a great job with the CoreBluetooth API, but because it enca

Aug 5, 2022

RxBluetoothKit is a Bluetooth library that makes interaction with BLE devices much more pleasant.

RxBluetoothKit is a Bluetooth library that makes interaction with BLE devices much more pleasant.

RxBluetoothKit is a Bluetooth library that makes interaction with BLE devices much more pleasant. It's backed by RxSwift and CoreBluetooth and it prov

Aug 9, 2022

Easily communicate between iOS/OSX devices using BLE

BluetoothKit Easily communicate between iOS devices using BLE. Background Apple mostly did a great job with the CoreBluetooth API, but because it enca

Aug 5, 2022

MacOS app which allows drag and drop of images to BLE thermal printers

MacOS app which allows drag and drop of images to BLE thermal printers

Print2BLE Copyright (c) 2021 BitBank Software, Inc. Written by Larry Bank [email protected] What is it? This project is a MacOS GUI applicatio

Jul 17, 2022

This is a simple app, which scans for BLE Peripherials and connect to them. The example works with NORDIC_UART_SERVICE.

This is a simple app, which scans for BLE Peripherials and connect to them. The example works with NORDIC_UART_SERVICE.

BLE Serial IOs Example This is a simple app, which scans for BLE Peripherials and connect to them. The example works with NORDIC_UART_SERVICE. UUIDS H

May 10, 2022

BLE (Bluetooth LE) for U๐ŸŽ Bleu is the best in the Bluetooth library.

BLE (Bluetooth LE) for U๐ŸŽ Bleu is the best in the Bluetooth library.

Bleu Bleu is a Bluetooth library. Bleu is the easiest way to operate CoreBluetooth. Bleu is possible to operate by replacing Bluetooth 's Peripheral a

Jun 29, 2022

The easiest way to use Bluetooth (BLE )in ios,even bady can use.

The easiest way to use Bluetooth (BLE )in ios,even bady can use.

The easiest way to use Bluetooth (BLE )in ios,even bady can use.

Aug 6, 2022

The TouchID authentication mechanism implemented in Swift.

iOS-TouchID-Swift The TouchID authentication mechanism implemented in Swift About In iOS 8, Apple provides a new framework named LocalAuthentication w

May 20, 2018

FCLAuthSwift is a Swift library for the Flow Client Library (FCL) that enables Flow wallet authentication on iOS devices.

FCLAuthSwift is a Swift library for the Flow Client Library (FCL) that enables Flow wallet authentication on iOS devices.

FCLAuthSwift is a Swift library for the Flow Client Library (FCL) that enables Flow wallet authentication on iOS devices. Demo The demo a

May 2, 2022

Very simple swift wrapper for Biometric Authentication Services (Touch ID) on iOS.

SimpleTouch Very simple swift wrapper for Biometric Authentication Services (Touch ID) on iOS. Sample Project There is a SimpleTouchDemo target define

Mar 18, 2022

An iOS passcode lock with TouchID authentication written in Swift.

An iOS passcode lock with TouchID authentication written in Swift.

PasscodeLock A Swift implementation of passcode lock for iOS with TouchID authentication. Installation PasscodeLock requires Swift 2.0 and Xcode 7 Car

Jul 27, 2022

An iOS passcode lock with TouchID authentication written in Swift.

An iOS passcode lock with TouchID authentication written in Swift.

PasscodeLock A Swift implementation of passcode lock for iOS with TouchID authentication. Originally created by @yankodimitrov, hope you're doing well

May 9, 2022

AuthenticationOverlay - A swift package for iOS and iPadOS which provides biometric authentication capablity along with a layer of obscurity

AuthenticationOverlay - A swift package for iOS and iPadOS which provides biometric authentication capablity along with a layer of obscurity

AuthenticationOverlay AuthenticationOverlay provides a lock screen along with Bi

Jan 26, 2022

Completed Project for Authentication in SwiftUI using Firebase Auth SDK & Sign in with Apple

Completed Project for Authentication in SwiftUI using Firebase Auth SDK & Sign in with Apple

Completed Project for Authentication in SwiftUI using Firebase Auth SDK & Sign in with Apple Follow the tutorial at alfianlosari.com Features Uses Fir

Mar 10, 2022

A passcode entry field for macOS similar to Apple's two-factor authentication field.

A passcode entry field for macOS similar to Apple's two-factor authentication field.

DSFPasscodeView A passcode entry field for macOS similar to Apple's two-factor authentication field. About The control is made up of multiple groups o

Jan 6, 2022

A UIViewController subclass for Instagram authentication.

A UIViewController subclass for Instagram authentication.

InstagramAuthViewController A ViewController for Instagram authentication. A UIViewController subclass that handles showing the Instagram login page,

Jun 29, 2021

A chat simulator app that uses FireBase for Authentication and chat storage

A chat simulator app that uses FireBase for Authentication and chat storage

Chat-App Description Flash chat is a chat simulator app that uses FireBase for Authentication and chat storage Tools Used - Swift (Programming Languag

Oct 14, 2021

Implementing User Authentication with Sign in with Apple

Implementing User Authentication with Sign in with Apple Provide a way for users of your app to set up an account and start using your services. Overv

Oct 18, 2021
Related tags
RxBluetoothKit is a Bluetooth library that makes interaction with BLE devices much more pleasant.
RxBluetoothKit is a Bluetooth library that makes interaction with BLE devices much more pleasant.

RxBluetoothKit is a Bluetooth library that makes interaction with BLE devices much more pleasant. It's backed by RxSwift and CoreBluetooth and it prov

Aug 9, 2022
MacOS app which allows drag and drop of images to BLE thermal printers
MacOS app which allows drag and drop of images to BLE thermal printers

Print2BLE Copyright (c) 2021 BitBank Software, Inc. Written by Larry Bank [email protected] What is it? This project is a MacOS GUI applicatio

Jul 17, 2022
This is a simple app, which scans for BLE Peripherials and connect to them. The example works with NORDIC_UART_SERVICE.
This is a simple app, which scans for BLE Peripherials and connect to them. The example works with NORDIC_UART_SERVICE.

BLE Serial IOs Example This is a simple app, which scans for BLE Peripherials and connect to them. The example works with NORDIC_UART_SERVICE. UUIDS H

May 10, 2022
BLE (Bluetooth LE) for U๐ŸŽ Bleu is the best in the Bluetooth library.
BLE (Bluetooth LE) for U๐ŸŽ Bleu is the best in the Bluetooth library.

Bleu Bleu is a Bluetooth library. Bleu is the easiest way to operate CoreBluetooth. Bleu is possible to operate by replacing Bluetooth 's Peripheral a

Jun 29, 2022
The easiest way to use Bluetooth (BLE )in ios,even bady can use.
The easiest way to use Bluetooth (BLE )in ios,even bady can use.

The easiest way to use Bluetooth (BLE )in ios,even bady can use.

Aug 6, 2022
Bluejay is a simple Swift framework for building reliable Bluetooth LE apps.
Bluejay is a simple Swift framework for building reliable Bluetooth LE apps.

Bluejay is a simple Swift framework for building reliable Bluetooth LE apps. Bluejay's primary goals are: Simplify talking to a single Bluetooth LE pe

Aug 3, 2022
An open-source Swift framework for building event-driven, zero-config Multipeer Connectivity apps

PeerKit An open-source Swift framework for building event-driven, zero-config Multipeer Connectivity apps Usage // Automatically detect and attach to

Aug 7, 2022
Bluetooth mapping in Swift
Bluetooth mapping in Swift

Bluetonium is part of the E-sites iOS Suite. Bluetonium is a Swift Library that makes it easy to communicate with Bluetooth devices. Features ?? Servi

Jul 19, 2022
FileManagerExample - File Manager Example With Swift

FileManagerExample FileManager๋ฅผ ์‰ฝ๊ฒŒ ์„ค๋ช…ํ•˜๊ธฐ ์œ„ํ•œ ๋ฌธ์„œ์ž…๋‹ˆ๋‹ค. let fileManager = FileMana

Jan 6, 2022
An app for questioning people to try on different names and pronouns. A winner of the Swift Student Challenge 2022.
An app for questioning people to try on different names and pronouns. A winner of the Swift Student Challenge 2022.

DiscoverMe is an app for questioning, trans, nonbinary, and gender-nonconforming people to try on different names and pronouns that better suit their

Jun 18, 2022