Skip to content

Commit

Permalink
Merge branch 'develop' into 'master'
Browse files Browse the repository at this point in the history
Develop

See merge request papers/airgap/beacon-android-sdk!65
  • Loading branch information
jsamol committed Oct 6, 2022
2 parents 222172b + 6d97515 commit 6d94c80
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 23 deletions.
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ To add `Beacon Android SDK` into your project:
#### Groovy
```groovy
dependencies {
def beacon_version = "3.2.0"
def beacon_version = "x.y.z"
// REQUIRED, core
implementation "com.github.airgap-it.beacon-android-sdk:core:$beacon_version"
Expand Down Expand Up @@ -76,7 +76,7 @@ To add `Beacon Android SDK` into your project:
#### Kotlin
```kotlin
dependencies {
val beaconVersion = "3.2.0"
val beaconVersion = "x.y.z"

// REQUIRED, core
implementation("com.github.airgap-it.beacon-android-sdk:core:$beaconVersion")
Expand Down Expand Up @@ -368,6 +368,12 @@ $ ./gradlew testMock{Release|Debug}UnitTest
---
## Related Projects

[Beacon SDK](https://github.com/airgap-it/beacon-sdk) - an SDK for web developers (dApp & wallet)
### AirGap Projects

[Beacon iOS SDK](https://github.com/airgap-it/beacon-ios-sdk) - an SDK for iOS developers (wallet)
[Beacon SDK](https://github.com/airgap-it/beacon-sdk) - an SDK for web developers

[Beacon iOS SDK](https://github.com/airgap-it/beacon-ios-sdk) - an SDK for iOS developers

### Community Projects

[Beacon Flutter SDK](https://github.com/TalaoDAO/beacon) - an SDK for Flutter developers
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ public data class MichelinePrimitiveBytes(public val bytes: String) : MichelineM

override fun deserialize(decoder: Decoder): MichelinePrimitiveBytes =
decoder.decodeStructure(descriptor) {
val primitive = decodeStringElement(descriptor, 0)
val primitive = HexString(decodeStringElement(descriptor, 0))

return MichelinePrimitiveBytes(primitive)
return MichelinePrimitiveBytes(primitive.asString(withPrefix = false))
}

override fun serialize(encoder: Encoder, value: MichelinePrimitiveBytes) {
encoder.encodeStructure(descriptor) {
with(value) {
encodeStringElement(descriptor, 0, HexString(bytes).asString(withPrefix = true))
encodeStringElement(descriptor, 0, HexString(bytes).asString(withPrefix = false))
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions buildSrc/src/main/java/GradleConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ object Android {
const val minSdk = 21
const val targetSdk = 32

const val versionCode = 25
const val versionName = "3.2.1"
const val versionCode = 27
const val versionName = "3.2.2"
}

object Version {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public value class HexString(private val value: String) {

public fun toByteArray(): ByteArray = asString().chunked(2).map { it.toInt(16).toByte() }.toByteArray()
public fun toInt(): Int = asString().toUInt(16).toInt()
public fun toBigInteger(): BigInteger = BigInteger(asString(), 16)
public fun toBigInteger(): BigInteger = BigInteger(asString().ifEmpty { "00" }, 16)

public fun slice(indices: IntRange): HexString = HexString(value.slice(indices))
public fun slice(startIndex: Int): HexString = HexString(value.substring(startIndex))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import androidx.annotation.RestrictTo
import it.airgap.beaconsdk.core.internal.data.HexString
import java.math.BigInteger

private val hexRegex: Regex = Regex("^(${HexString.PREFIX})?([0-9a-fA-F]{2})+$")
private val hexRegex: Regex = Regex("^(${HexString.PREFIX})?([0-9a-fA-F]{2})*$")

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public fun String.isHex(): Boolean = this.matches(hexRegex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ import kotlin.test.assertFailsWith

internal class HexStringTest {
private val validHexStrings: List<String> = listOf(
"",
"9434dc98",
"0x7b1ea2cb",
"e40476d7",
"c47320abdd31",
"0x5786dac9eaf4",
"0x",
)

private val invalidHexStrings: List<String> = listOf(
"",
"9434dc98az",
"0xe40476d77t",
"0x",
"0x1",
)

Expand Down Expand Up @@ -122,7 +122,7 @@ internal class HexStringTest {
@Test
fun `creates BigInteger from HexString`() {
val hexStringsWithExpected: List<Pair<String, BigInteger>> =
validHexStrings.map { it to BigInteger(withoutHexPrefix(it), 16) }
validHexStrings.map { it to BigInteger(withoutHexPrefix(it).ifEmpty { "00" }, 16) }

hexStringsWithExpected
.map { it.first.asHexString().toBigInteger() to it.second }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import java.math.BigInteger

internal class BytesTest {
private val validHexStrings: List<String> = listOf(
"",
"9434dc98",
"0x7b1ea2cb",
"e40476d7",
"c47320abdd31",
"0x5786dac9eaf4",
"0x",
)

private val invalidHexStrings: List<String> = listOf(
"",
"9434dc98az",
"0xe40476d77t",
"0x",
"0x1",
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import it.airgap.beaconsdk.core.message.BeaconResponse
import it.airgap.beaconsdkdemo.R
import it.airgap.beaconsdkdemo.utils.toJson
import kotlinx.android.synthetic.main.fragment_dapp.*
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,14 @@ class DAppFragmentViewModel : ViewModel() {
viewModelScope.launch {
val beaconClient = beaconClient ?: return@launch

val pairingRequest = beaconClient.pair()
val serializerPairingRequest = beaconClient.serializePairingData(pairingRequest)

_state.emit { copy(pairingRequest = serializerPairingRequest) }
try {
val pairingRequest = beaconClient.pair()
val serializerPairingRequest = beaconClient.serializePairingData(pairingRequest)

_state.emit { copy(pairingRequest = serializerPairingRequest) }
} catch (e: Throwable) {
onError(e)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,13 @@ class WalletFragmentViewModel : ViewModel() {
/* Others */
else -> ErrorBeaconResponse.from(request, BeaconError.Unknown)
}
beaconClient.respond(response)
removeAwaitingRequest()

try {
beaconClient.respond(response)
removeAwaitingRequest()
} catch (e: Throwable) {
onError(e)
}
}
}

Expand Down

0 comments on commit 6d94c80

Please sign in to comment.