Skip to content
Binance implementation of Wallet Connect protocol as kotlin library
Kotlin
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
app
gradle/wrapper
wallet-connect
.gitignore
LICENSE
README.md
build.gradle
gradle.properties
gradlew
gradlew.bat
settings.gradle

README.md

Wallet Connect Android

Wallet Connect Android is a library writen in Kotlin which implements WalletConnect protocol(only binance actions). Library is highly inspired by swift-walletconnect-lib

Download

Using Gradle:

repositories {
	...
	maven {url "https://jitpack.io"}
}

dependencies {
	implementation 'com.github.paytomat:wallet-connect-android:0.9.2'
}

Proguard

Add to you proguard file following lines:

-keep class com.paytomat.walletconnect.android.model.* { *; }

Usage

To start WC session you must specify SessionInfo and Client metadata:

val wcString: String = "wc:eb07cd88-45b5-4ced-891d-6475ff1fc548@1?bridge=https%3A%2F%2Fwallet-bridge.binance.org&key=88dabccbf7b006c74ed80543108c26ada67fd893ce3b6997c18459d5f6aa4c2b"//scanned wallet connect QR-code
val clientMeta = WCPeerMeta("WalletConnect SDK", "https://github.com/Paytomat/wallet-connect-android")
val uuid: String = "specify UUID here"
val interactor = WCInteractor(session, clientMeta, uuid)

Add callbacks by implementing WCCallbacks inteface:

override fun onSessionRequest(id: Long, peer: WCPeerMeta) {
	//Handle request for session start here
}

override fun onStatusUpdate(status: Status) {
	//Handle connection status here
}

override fun onBnbSign(id: Long, order: WCBinanceOrder<*>) {
	//Handle bnb order here
}

Set callbacks of interactor:

interactor.callbacks = this

NOTE: callbacks are called from thread where message were received, so if you do some UI action make sure to move action to UI thread

Approve session:

interactor.approveSession(arrayOf(yourBnbAddress), yourChainIdInt)

Reject session

interactor.rejectSession()
interactor.killSession()//drop socket connection

Approve BNB order

override fun onBnbSign(id: Long, order: WCBinanceOrder<*>) {
	//Serialize JSON to string with nulls
	val orderString: String = GsonBuilder().serializeNulls().create().toJson(order)
	//Sign message
	val signature: ByteArray = Signature.signMessage(orderJson.toByteArray(), privateKey)
	//Form order signature message
	val signed = WCBinanceOrderSignature(Hex.toHexString(signature), Hex.toHexString(privateKey.publicKey.bytes))
    	//Send message
   	interactor.approveBnbOrder(id, signed)
}

Reject BNB order

override fun onBnbSign(id: Long, order: WCBinanceOrder<*>) {
	interactor.rejectRequest(id, "Rejected")
}

Tested with:

You can’t perform that action at this time.