The Mixin Network based wallet allows for the rapid construction of decentralized wallets, decentralized on-chain exchanges, and other products.
- iOS 13.0 or later
Add it in Podfile
pod 'MixinAPI'
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)
}
Some basic usages are demonstrated with the demo. Follow the steps below to try it:
- Clone the repo
- Run
pod install
in the repo's root folder - Open
MixinAPI.xcworkspace
generated by previous step - Fill your credentials in AccountViewModel.swift
- Run
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.
- Report bugs in a Github issue.
- Access our developers group of Mixin ID 7000104112.
APIs are grouped and provided through an API
object. Initialize it with a valid session to access them.
You need to provide several credentials to intialize an API.AuthenticatedSession
.
userID
client_id
provided by developer's dashboard for bots, oruser_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 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 protocolPINIterator
, and provide an incremented value each time whenvalue()
is called.
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.
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 ifUser.hasPIN
is false.
AccountWorker.logs(offset:category:limit:completion:)
Get user's log.
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, callAssetWorker.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
anddestination
,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.
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.
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.
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.
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.
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.