https://github.com/mixinnetwork/bot-api-swift-client
https://github.com/mixinnetwork/bot-api-swift-client
Last synced: 12 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/mixinnetwork/bot-api-swift-client
- Owner: MixinNetwork
- License: mit
- Created: 2022-05-05T05:49:29.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-10-10T15:39:50.000Z (over 3 years ago)
- Last Synced: 2025-06-22T06:54:12.956Z (12 months ago)
- Language: Swift
- Size: 219 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# bot-api-swift-client
[](https://cocoapods.org/pods/MixinAPI)
The [Mixin Network](https://mixin.one/) based wallet allows for the rapid construction of decentralized wallets, decentralized on-chain exchanges, and other products.
# Requirements
- iOS 13.0 or later
# Installation
## Cocoapods
Add it in Podfile
```
pod 'MixinAPI'
```
# Usage
```swift
let client = Client(userAgent: "YourApp 0.1.0")
let iterator = CurrentTimePINIterator()
let session = try API.AuthenticatedSession(userID: userID,
sessionID: sessionID,
pinToken: pinToken,
privateKey: privateKey,
client: client,
hostStorage: WalletHost(),
pinIterator: iterator,
analytic: consoleOutput)
let api = API(session: session)
api.account.me { result in
print(result)
}
```
# Demo
Some basic usages are demonstrated with the demo. Follow the steps below to try it:
1. Clone the repo
2. Run `pod install` in the repo's root folder
3. Open `MixinAPI.xcworkspace` generated by previous step
4. Fill your credentials in [AccountViewModel.swift](https://github.com/MixinNetwork/bot-api-swift-client/blob/main/WalletDemo/WalletDemo/View%20Model/AccountViewModel.swift)
5. Run
# About PIN
A 6-digit PIN is required when a user is trying to transfer assets, the code functions pretty much like a private key, not retrievable if lost.
- There is a time lock for PIN errors. If you have failed 5 times a day, do not try again, even the PIN is correct after 5 times, an error will be returned. Repeating more times will cause a longer lock time. It is recommended that users write down the tried PIN and try again the next day.
- Once a PIN is lost, it can never be retrieved. It is recommended that the developer let each user enter it regularly to help memorize it. During the initial setting, make sure to let the user enter it more than 3 times and remind the user that it cannot be retrieved if lost
- For asset security, it is recommended to remind users not to set PINs that are too simple or common combinations, such as 123456, 111222.
# Support
- Report bugs in a [Github issue](https://github.com/MixinNetwork/bot-api-swift-client/issues/new).
- Access our developers group of Mixin ID 7000104112.
# API Essentials
## Overview
APIs are grouped and provided through an `API` object. Initialize it with a valid session to access them.
## Authenticated Session
You need to provide several credentials to intialize an `API.AuthenticatedSession`.
- `userID`
> `client_id` provided by developer's dashboard for bots, or `user_id` of messenger users.
- `sessionID`
- `pinToken`
- `privateKey`
> An ed25519 private key, which provided by developer's dashboard for bots, or generated by calling `Ed25519PrivateKey()` for messenger users.
- `hostStorage`
> Stores current host index. When a bad network is detected, API may try again by switching to another host.
> See [WalletHost.swift](https://github.com/MixinNetwork/bot-api-swift-client/blob/main/WalletDemo/WalletDemo/Foundation/WalletHost.swift) for example.
- `pinIterator`
> PIN is encrypted with an iterator, which must be incremental and greater than 0. You can pick `CurrentTimePINIterator` to use the current system time as iterator's value, or implement one by yourself with custom value provided. Custom PIN iterator should conforms to protocol `PINIterator`, and provide an incremented value each time when `value()` is called.
## Notifications
- `API.unauthorizedNotification`
> This notification will be posted when the session is considered unauthorized. This may happens when a bot's credential is reset. You can tear down UI components when this notification is received.
- `API.clockSkewDetectedNotification`
> Mixin API must be called with system time being accurated, otherwise all requests will be failed. If a significant clock skew is detected, this notification will be posted, you may observe this notification to tell end users to check their time settings.
# Account APIs
- `AccountWorker.me(completion:)`
> Get the current user's personal information.
- `AccountWorker.update(fullName:biography:avatarBase64:completion:)`
> Update user's profile.
- `AccountWorker.verify(pin:completion:)`
> Verify PIN.
- `AccountWorker.updatePIN(old:new:completion:)`
> Update PIN.
> ℹ️ `old` should be nil if `User.hasPIN` is false.
- `AccountWorker.logs(offset:category:limit:completion:)`
> Get user's log.
# Asset APIs
- `AssetWorker.assets(queue:completion:)`
> Request user's asset list.
> ℹ️ Assets responded with this API may have an empty `depositEntries`. If you want a deposit address, call `AssetWorker.asset(assetID:completion:)` with a specific asset ID to get one.
- `AssetWorker.snapshots(limit:offset:assetID:opponentID:destination:tag:queue:completion:)`
> Get the snapshots by several filters. `opponent` and `destination`, `tag` can't use together, both of them don't support order.
- `AssetWorker.fee(assetID:completion:)`
> Get the specified asset's fee.
- `AssetWorker.pendingDeposits(assetID:destination:tag:completion:)`
> Get public network-wide deposit records.
- `AssetWorker.search(keyword:completion:)`
> Search asset with specific keyword.
- `AssetWorker.topAssets(completion:)`
> Get current trendings.
- `AssetWorker.fiats(completion:)`
> Returns a list of all fiat exchange rates based on US Dollar.
- `AssetWorker.ticker(asset:offset:completion:)`
> Get the historical price of a given asset.
# Collectible APIs
- `CollectibleWorker.sign(requestID:pin:completion:)`
> Sign collectible request.
- `CollectibleWorker.unlock(requestID:pin:completion:)`
> Unlock collectible request.
- `CollectibleWorker.cancel(requestID:completion:)`
> Cancel collectible request.
- `CollectibleWorker.token(tokenID:)`
> Get the information of the collectible.
# Multisig APIs
- `MultisigWorker.sign(requestID:pin:completion:)`
> Sign multisig request.
- `MultisigWorker.unlock(requestID:pin:completion:)`
> Send multisig unlocking request.
- `MultisigWorker.cancel(requestID:completion:)`
> Send multisig cancelling request.
# Payment APIs
- `PaymentWorker.payments(assetID:opponentID:amount:traceID:)`
> Transfer to an opponent with specific ID.
- `PaymentWorker.payments(assetID:addressID:amount:traceID:)`
> Transfer to an address with specific ID.
- `PaymentWorker.transactions(transactionRequest:pin:completion:)`
> Transfer to a specified multisig address.
- `PaymentWorker.transfer(assetID:opponentID:amount:memo:pin:traceID:completion:)`
> Transfer to an opponent with specific ID.
# Snapshot APIs
- `SnapshotWorker.snapshot(snapshotID:completion:)`
> Get the snapshot of a user by id.
> ℹ️ If the snapshot is not of the current user, `MixinError.forbidden` will be returned.
- `SnapshotWorker.trace(traceID:)`
> Get the snapshot corresponding to specific trace ID.
# Withdrawal APIs
- `WithdrawalWorker.address(addressID:completion:)`
> Get the address with specifice id.
- `WithdrawalWorker.addresses(assetID:completion:)`
> Get a list of withdrawal addresses for the given asset.
- `WithdrawalWorker.save(address:completion:)`
> Create a new withdrawal address.
- `WithdrawalWorker.withdrawal(withdrawal:completion:)`
> Submit a withdrawal request.
> ℹ️ It costs fee to withdrawal. To get the fee, use `AssetWorker.fee(assetID:completion:)`.
- `WithdrawalWorker.delete(addressID:pin:completion:)`
> Delete a specified address by it's id.