Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/e2e-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ jobs:
script: cd bitkit-e2e-tests && ./ci_run_android.sh --mochaOpts.grep "${{ matrix.shard.grep }}"
env:
BACKEND: regtest
BLOCKTANK_REGTEST_AUTH: ${{ secrets.BLOCKTANK_REGTEST_AUTH }}
RECORD_VIDEO: true
ATTEMPT: 1

Expand All @@ -204,6 +205,7 @@ jobs:
script: cd bitkit-e2e-tests && ./ci_run_android.sh --mochaOpts.grep "${{ matrix.shard.grep }}"
env:
BACKEND: regtest
BLOCKTANK_REGTEST_AUTH: ${{ secrets.BLOCKTANK_REGTEST_AUTH }}
RECORD_VIDEO: true
ATTEMPT: 2

Expand All @@ -221,6 +223,7 @@ jobs:
script: cd bitkit-e2e-tests && ./ci_run_android.sh --mochaOpts.grep "${{ matrix.shard.grep }}"
env:
BACKEND: regtest
BLOCKTANK_REGTEST_AUTH: ${{ secrets.BLOCKTANK_REGTEST_AUTH }}
RECORD_VIDEO: true
ATTEMPT: 3

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/e2e_migration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ jobs:
name: android - ${{ matrix.scenario.version }} - ${{ matrix.scenario.name }}
env:
BACKEND: regtest
BLOCKTANK_REGTEST_AUTH: ${{ secrets.BLOCKTANK_REGTEST_AUTH }}
MIGRATION_EXTENDED: ${{ inputs.extended_rn || false }}

steps:
Expand Down
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [3.1.1] - 2026-11-12

### Added
- Bitkit now uses your pubky.app profile, so edits in Bitkit and on pubky.app show in both. #1801

### Fixed
- Fixed an occasional app freeze on launch while Pubky contacts start up. #1798
- Paykit payment requests now check that a payment proof fits before paying, explain notes that are too long and refused signup codes, and no longer count a USDT transfer sent before its request as payment. #1803

### Security
- Updated the Lightning node with upstream security fixes. #1870
- Updated the VSS client and Paykit with upstream rustls security fixes. #1824, #1873

## [3.1.0] - 2026-11-02

### Added
Expand Down Expand Up @@ -431,7 +444,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- About screen (content merged into Support) #857
- Standalone General, Security, and Advanced settings screens (merged into tabs) #857

[Unreleased]: https://github.com/synonymdev/bitkit-android/compare/v3.1.0...HEAD
[Unreleased]: https://github.com/synonymdev/bitkit-android/compare/v3.1.1...HEAD
[3.1.1]: https://github.com/synonymdev/bitkit-android/compare/v3.1.0...v3.1.1
[3.1.0]: https://github.com/synonymdev/bitkit-android/compare/v3.0.1...v3.1.0
[3.0.1]: https://github.com/synonymdev/bitkit-android/compare/v3.0.0..v3.0.1
[3.0.0]: https://github.com/synonymdev/bitkit-android/compare/v2.5.1..v3.0.0
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ android {
applicationId = "to.bitkit"
minSdk = 28
targetSdk = 36
versionCode = 196
versionName = "3.1.0"
versionCode = 197
versionName = "3.1.1"
testInstrumentationRunner = "to.bitkit.test.HiltTestRunner"
bitkitAndroidTestAnnotation?.let {
testInstrumentationRunnerArguments["annotation"] = it
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/to/bitkit/async/ServiceQueue.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import java.util.concurrent.ThreadFactory
import kotlin.coroutines.CoroutineContext

enum class ServiceQueue {
LDK, CORE, FOREX, LOG, MIGRATION;
LDK, CORE, PUBKY, FOREX, LOG, MIGRATION;

private val scope by lazy { CoroutineScope(newSingleThreadDispatcher(name) + SupervisorJob()) }

Expand Down
12 changes: 11 additions & 1 deletion app/src/main/java/to/bitkit/data/PubkyStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,14 @@ class PubkyStore @Inject constructor(
store.updateData(transform)
}

/** Clears the session's data but keeps the migration history, so a profile deleted on pubky.app stays deleted. */
suspend fun reset() {
store.updateData { PubkyStoreData() }
store.updateData {
PubkyStoreData(
pubkyAppProfileOwners = it.pubkyAppProfileOwners,
pubkyAppAvatarPending = it.pubkyAppAvatarPending,
)
}
}
}

Expand All @@ -41,6 +47,10 @@ data class PubkyStoreData(
val cachedName: String? = null,
val cachedImageUri: String? = null,
val contactProfileOverrides: Map<String, PubkyProfileData> = emptyMap(),
/** Identities Bitkit has seen a pubky.app profile for, so a profile deleted there is not moved back from Bitkit. */
val pubkyAppProfileOwners: Set<String> = emptySet(),
/** Identities whose Bitkit avatar is still to be moved to pubky.app, retried on each profile load. */
val pubkyAppAvatarPending: Set<String> = emptySet(),
) {
fun cachedProfile(): PubkyCachedProfile? = cachedProfileOwner?.let {
PubkyCachedProfile(publicKey = it, name = cachedName.orEmpty(), imageUri = cachedImageUri)
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/to/bitkit/ext/PaykitExceptionExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ package to.bitkit.ext

import com.synonym.paykit.PaykitException

/** Protocol error code for an outbound Private Application Message larger than one pubky-noise message. */
private const val MESSAGE_TOO_LARGE_CODE = "message_too_large"

/** Identity error code for a signup code the homeserver refused during sign-up. */
private const val SIGNUP_CODE_REJECTED_CODE = "signup_code_rejected"

fun Throwable.isPaykitIdentityError(): Boolean =
generateSequence(this) { it.cause }.any { it is PaykitException.Identity }

Expand All @@ -13,3 +19,9 @@ fun Throwable.isPaykitTemporarilyUnavailable(): Boolean =
it is PaykitException.ConcurrentUpdate || it is PaykitException.SharedStateBusy ||
it is PaykitException.Transport
}

fun Throwable.isPaykitMessageTooLarge(): Boolean =
generateSequence(this) { it.cause }.any { it is PaykitException.Protocol && it.code == MESSAGE_TOO_LARGE_CODE }

fun Throwable.isPaykitSignupCodeRejected(): Boolean =
generateSequence(this) { it.cause }.any { it is PaykitException.Identity && it.code == SIGNUP_CODE_REJECTED_CODE }
5 changes: 3 additions & 2 deletions app/src/main/java/to/bitkit/models/PaykitUsdtStateBackup.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,17 @@ data class PaykitUsdtStateBackup(
val receivedAtMillis: Long,
val underpaid: Boolean,
val afterExpiry: Boolean,
val beforeRequest: Boolean = false,
) {
constructor(value: PaykitUsdtReceipt) : this(
value.wallet, value.identity, value.requestId, value.paymentId, value.proofEventId,
value.verified, value.transferId, value.amount.atomic, value.receivedAtMillis,
value.underpaid, value.afterExpiry,
value.underpaid, value.afterExpiry, value.beforeRequest,
)

fun restored() = PaykitUsdtReceipt(
wallet, identity, requestId, paymentId, proofEventId, verified, transferId,
PaykitAmount(PaykitAsset.USDT, amountAtomic), receivedAtMillis, underpaid, afterExpiry,
PaykitAmount(PaykitAsset.USDT, amountAtomic), receivedAtMillis, underpaid, afterExpiry, beforeRequest,
)
}
}
12 changes: 12 additions & 0 deletions app/src/main/java/to/bitkit/models/PubkyProfile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ import com.synonym.paykit.PubkyProfile as SdkPubkyProfile

private val pubkyProfileJson = Json { ignoreUnknownKeys = true }

/** pubky.app profile name limits from pubky-app-specs. */
const val PROFILE_NAME_MIN_LENGTH = 3
const val PROFILE_NAME_MAX_LENGTH = 50
const val PROFILE_LINKS_MAX_COUNT = 5

/** pubky.app counts code points, not UTF-16 chars. */
fun isValidProfileName(name: String) = name.trim().let { it.codePointCount(0, it.length) } in
PROFILE_NAME_MIN_LENGTH..PROFILE_NAME_MAX_LENGTH

fun String.takeCodePoints(max: Int) =
if (codePointCount(0, length) <= max) this else substring(0, offsetByCodePoints(0, max))

@Immutable
data class PubkyProfileLink(val label: String, val url: String)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,22 @@ class PaykitAllowanceExecutor @Inject constructor(
Logger.info("Kept an incoming request manual: the payee offers no Lightning invoice", context = TAG)
return PaykitAllowanceAutoPayResult.MANUAL
}
// Measured before the acceptance, so a proof that can never be delivered is never accepted on the payee's side.
val proofFits = runSuspendCatching {
paykitSdkService.requirePaymentProofFits(
paymentReference = request.paymentReference,
paymentAppId = payment.appId,
paymentEndpointIdentifier = payment.endpoint.methodId.rawValue,
kind = PaykitPaymentProofKind.Lightning,
billingPeriod = request.billingPeriod,
conversionQuoteId = null,
allowanceId = candidate.allowanceId,
)
}.isSuccess
if (!proofFits) {
Logger.info("Kept an incoming request manual: its payment proof would not fit one message", context = TAG)
return PaykitAllowanceAutoPayResult.MANUAL
}

if (!admits(activation)) {
Logger.info("Kept an incoming request manual: allowances turned off before acceptance", context = TAG)
Expand Down
75 changes: 75 additions & 0 deletions app/src/main/java/to/bitkit/repositories/PaykitPaymentProofRepo.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package to.bitkit.repositories

import com.synonym.bitkitcore.UsdtPaymentProof
import com.synonym.paykit.BillingPeriod
import com.synonym.paykit.PaymentProofRecord
import com.synonym.paykit.PaymentRequestLifecycleState
Expand Down Expand Up @@ -41,6 +42,7 @@ import to.bitkit.ext.toHex
import to.bitkit.models.HwFundingSignedTx
import to.bitkit.models.PaykitPaymentStateBackup
import to.bitkit.models.PaykitRequestPayment
import to.bitkit.models.PaykitUsdt
import to.bitkit.models.PubkyPublicKeyFormat
import to.bitkit.models.WalletScope
import to.bitkit.services.PaykitSdkOperationLock
Expand Down Expand Up @@ -203,6 +205,15 @@ class PaykitPaymentProofRepo @Inject constructor(
) {
throw PaykitPaymentRequestError.RequestUnavailable
}
paykitSdkService.requirePaymentProofFits(
paymentReference = request.paymentReference,
paymentAppId = paymentAppId,
paymentEndpointIdentifier = paymentEndpointIdentifier,
kind = kind,
billingPeriod = request.billingPeriod,
conversionQuoteId = paymentTerms?.quoteId,
allowanceId = allowanceId,
)
val read = paykitSdkService.readPaymentRequests(request.counterparty)
val identityStatus = read.identityStatus
val identity = identityStatus?.publicKey?.let(PubkyPublicKeyFormat::normalized)
Expand Down Expand Up @@ -1684,6 +1695,70 @@ private fun proofJson(kind: PaykitPaymentProofKind, data: String): String {
}.toString()
}

/** Hex length of the 32-byte preimage or transaction id a Bitcoin proof carries. */
private const val BITCOIN_PROOF_DATA_LENGTH = 64

/** Hex digits of a 32-byte ERC-20 transaction hash after its `0x` prefix. */
private const val USDT_TRANSACTION_HASH_DIGITS = 64

/** Hex digits of a 65-byte EIP-712 signature after its `0x` prefix. */
private const val USDT_SIGNATURE_DIGITS = 130

/** The largest uint256 receipt log index, the longest one the SDK accepts in an ERC-20 proof. */
internal const val USDT_MAX_RECEIPT_LOG_INDEX =
"115792089237316195423570985008687907853269984665640564039457584007913129639935"

/** The longest proof Bitkit submits for this kind, so a measured proof is never shorter than the one sent. */
internal fun PaykitPaymentProofKind.longestProofJson(): String = when (this) {
PaykitPaymentProofKind.Usdt -> Json.encodeToString(
PaykitUsdtProof.serializer(),
PaykitUsdtProof(
UsdtPaymentProof(
chainId = PaykitUsdt.CHAIN_ID,
transactionHash = "0x" + "0".repeat(USDT_TRANSACTION_HASH_DIGITS),
receiptLogIndex = USDT_MAX_RECEIPT_LOG_INDEX,
signature = "0x" + "0".repeat(USDT_SIGNATURE_DIGITS),
),
),
)
PaykitPaymentProofKind.Lightning, PaykitPaymentProofKind.Onchain ->
proofJson(this, "0".repeat(BITCOIN_PROOF_DATA_LENGTH))
}

/** Log context for measuring a Payment Proof before payment. */
private const val PROOF_SIZE_TAG = "PaykitProofSize"

/**
* Fails with [PaykitPaymentRequestError.RequestUnavailable] when the longest proof of [kind] for these values would
* not fit one Private Application Message, or cannot be measured, so nothing is paid for a proof that could never be
* delivered.
*/
internal fun PaykitSdkService.requirePaymentProofFits(
paymentReference: String,
paymentAppId: String,
paymentEndpointIdentifier: String,
kind: PaykitPaymentProofKind,
billingPeriod: PaykitBillingPeriod?,
conversionQuoteId: String?,
allowanceId: String?,
) {
val length = runCatching {
paymentProofEventLength(
paymentReference = paymentReference,
paymentAppId = paymentAppId,
paymentEndpointIdentifier = paymentEndpointIdentifier,
proofJson = kind.longestProofJson(),
billingPeriod = billingPeriod,
conversionQuoteId = conversionQuoteId,
allowanceId = allowanceId,
)
}.getOrElse {
Logger.warn("Failed to measure a Paykit payment proof", it, context = PROOF_SIZE_TAG)
throw PaykitPaymentRequestError.RequestUnavailable
}
if (length > PaykitSdkService.MAX_MESSAGE_BYTES.toUInt()) throw PaykitPaymentRequestError.RequestUnavailable
}

private fun String.proofValues(): JsonObject? = runCatching { Json.parseToJsonElement(this).jsonObject }.getOrNull()

private fun String.matchesPaymentHash(paymentHash: String): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import to.bitkit.data.SettingsStore
import to.bitkit.di.IoDispatcher
import to.bitkit.di.SubscriptionClock
import to.bitkit.env.Env
import to.bitkit.ext.isPaykitMessageTooLarge
import to.bitkit.ext.runSuspendCatching
import to.bitkit.flags.PaykitFeatureFlags
import to.bitkit.models.PaykitAmount
Expand Down Expand Up @@ -307,6 +308,7 @@ sealed class PaykitPaymentRequestError(message: String) : AppError(message) {
data object RequestExpired : PaykitPaymentRequestError("Payment request has expired")
data object OperationInProgress : PaykitPaymentRequestError("Payment request operation is already in progress")
data object SubscriptionTooLong : PaykitPaymentRequestError("Subscription proposal exceeds the message size limit")
data object RequestTooLong : PaykitPaymentRequestError("Payment request proposal exceeds the message size limit")
}

enum class PaykitPaymentRequestRefreshMode {
Expand Down Expand Up @@ -898,10 +900,11 @@ class PaykitPaymentRequestRepo @Inject constructor(
proposalDate
)
actionVersion++
val record = paykitSdkService.proposePaymentRequest(
val record = proposeWithinMessageLimit(
counterparty = target.publicKey,
proposal = proposal,
expectedIdentity = expectedIdentity,
tooLong = PaykitPaymentRequestError.RequestTooLong,
)
val reports = processPendingMessages(target.publicKey)

Expand All @@ -924,6 +927,19 @@ class PaykitPaymentRequestRepo @Inject constructor(
}
}

private suspend fun proposeWithinMessageLimit(
counterparty: String,
proposal: PaykitPaymentRequestProposalTerms,
expectedIdentity: String,
tooLong: PaykitPaymentRequestError,
): PaymentRequestRecord = runSuspendCatching {
paykitSdkService.proposePaymentRequest(
counterparty = counterparty,
proposal = proposal,
expectedIdentity = expectedIdentity,
)
}.getOrElse { throw if (it.isPaykitMessageTooLarge()) tooLong else it }

private fun buildPaymentRequestProposal(
draft: PaykitPaymentRequestDraft,
endpointIdentifiers: List<String>,
Expand Down Expand Up @@ -996,10 +1012,11 @@ class PaykitPaymentRequestRepo @Inject constructor(
val proposal = buildSubscriptionProposal(draft, name, description, iconUri, endpoints, clock.now())
PaykitSubscriptionProposal.validate(proposal)
actionVersion++
val record = paykitSdkService.proposePaymentRequest(
val record = proposeWithinMessageLimit(
counterparty = target.publicKey,
proposal = proposal,
expectedIdentity = expectedIdentity,
tooLong = PaykitPaymentRequestError.SubscriptionTooLong,
)
val reports = processPendingMessages(target.publicKey)
val deliveryStatus = if (proposalWasSent(record, reports, generation, expectedIdentity)) {
Expand Down
Loading
Loading