Skip to content

Commit

Permalink
update: added signature for paybis
Browse files Browse the repository at this point in the history
  • Loading branch information
Petar Sebic committed Oct 22, 2024
1 parent f99b8d8 commit 9f4a658
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ android {
buildConfigField "String", "API_KEY_RARIBLE", "\"${properties.getProperty("API_KEY_RARIBLE")}\""
buildConfigField "String", "API_KEY_COVALENT", "\"${properties.getProperty("API_KEY_COVALENT")}\""
buildConfigField "String", "PARTNER_UUID", "\"${properties.getProperty("PARTNER_UUID")}\""
buildConfigField "String", "HMAC_KEY", "\"${properties.getProperty("HMAC_KEY")}\""
}

buildTypes {
Expand Down
22 changes: 19 additions & 3 deletions app/src/main/java/org/satochip/satodimeapp/Navigation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context
import android.content.pm.ActivityInfo
import android.os.Build
import androidx.annotation.RequiresApi
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalUriHandler
Expand Down Expand Up @@ -41,9 +43,14 @@ import org.satochip.satodimeapp.util.SatodimePreferences
import org.satochip.satodimeapp.util.SatodimeScreen
import org.satochip.satodimeapp.util.apiKeys
import org.satochip.satodimeapp.viewmodels.SharedViewModel
import java.net.URLEncoder
import java.util.Base64
import javax.crypto.Mac
import javax.crypto.spec.SecretKeySpec

private const val TAG = "Navigation"

@RequiresApi(Build.VERSION_CODES.O)
@SuppressLint("SourceLockedOrientationActivity")
@Composable
fun Navigation() {
Expand Down Expand Up @@ -172,12 +179,21 @@ fun Navigation() {
val cardVault = cardVaults[selectedVault - 1]!!
val depositAddress = cardVault.nativeAsset.address
val apiKey = apiKeys["PARTNER_UUID"]
val uri = "https://widget.paybis.com/" +
"?partnerId=$apiKey" +
val hmacKey = apiKeys["HMAC_KEY"]
val uri = "https://widget.paybis.com/"
val query = "?partnerId=$apiKey" +
"&cryptoAddress=$depositAddress" +
"&currencyCodeFrom=EUR" +
"&currencyCodeTo=${cardVault.nativeAsset.symbol}"
uriHandler.openUri(uri)
val decodedKey = Base64.getDecoder().decode(hmacKey)
val mac = Mac.getInstance("HmacSHA256")
val secretKeySpec = SecretKeySpec(decodedKey, "HmacSHA256")
mac.init(secretKeySpec)
val signatureBytes = mac.doFinal(query.toByteArray(Charsets.UTF_8))
val signature = Base64.getEncoder().encodeToString(signatureBytes)
val encodedSignature = URLEncoder.encode(signature, "UTF-8")

uriHandler.openUri("$uri$query&signature=$encodedSignature")
}
)
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/org/satochip/satodimeapp/util/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ val apiKeys = hashMapOf(
Pair("API_KEY_RARIBLE", BuildConfig.API_KEY_RARIBLE),
Pair("API_KEY_COVALENT", BuildConfig.API_KEY_COVALENT),
Pair("PARTNER_UUID", BuildConfig.PARTNER_UUID),
Pair("HMAC_KEY", BuildConfig.HMAC_KEY),
)

/** Convert an IPFS address to IPFS gateway (https) address */
Expand Down

0 comments on commit 9f4a658

Please sign in to comment.