Swift implementation of Xiaomi's BLE authentication

Related tags

Bluetooth miauth
Overview

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.

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

The Bluetooth LE library for iOS and Mac. 100% Swift.
The Bluetooth LE library for iOS and Mac. 100% Swift.

iOS-BLE-Library An in-development Bluetooth Low Energy Library by Nordic Semiconductor to interact with the , which is not complicated, but requires w

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

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

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

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

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

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

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.

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

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

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

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

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

AuthenticationOverlay - A swift package for iOS and iPadOS which provides biometric authentication capablity along with a layer of obscurity 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

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

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,

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

Owner
null
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

Polidea 1.3k Jan 6, 2023
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

Larry Bank 37 Jan 5, 2023
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

Muhammad Hammad 4 May 10, 2022
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

1amageek 484 Dec 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.

刘彦玮 4.6k Dec 27, 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's primary goals are: Simplify talking to a single Bluetooth LE pe

Steamclock Software 1k Dec 13, 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

JP Simard 861 Dec 23, 2022
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

E-sites 165 Nov 20, 2022
FileManagerExample - File Manager Example With Swift

FileManagerExample FileManager를 쉽게 설명하기 위한 문서입니다. let fileManager = FileMana

Jackson 0 Jan 6, 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

Joshua Tint 6 Oct 2, 2022