Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mdavis/kt uma invoice #54

Merged
merged 11 commits into from
Aug 22, 2024
252 changes: 252 additions & 0 deletions .idea/other.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ kotlin = "1.9.0"
kotlinCoroutines = "1.6.4"
kotlinxDateTime = "0.4.0"
kotlinSerializationJson = "1.4.1"
kotlinReflect = "2.0.0"
ktlint = "11.3.1"
ktor = "2.2.3"
mavenPublish = "0.25.2"
mockitoCore = "5.5.0"
taskTree = "2.1.1"
junit = "4.13.2"
bitcoinj-core = "0.16.3"

[libraries]
gradleClasspath-dokka = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref = "dokka" }
Expand Down
1 change: 1 addition & 0 deletions uma-sdk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ kotlin {
implementation(libs.kotlinx.coroutines.core)
implementation(libs.ktor.client.core)
implementation(libs.jna)
implementation(kotlin("reflect"))
}
}
val commonTest by getting {
Expand Down
37 changes: 37 additions & 0 deletions uma-sdk/src/commonMain/kotlin/me/uma/UmaProtocolHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,43 @@ class UmaProtocolHelper @JvmOverloads constructor(
}
return identifier.substring(atIndex + 1)
}

/**
* Create an UMA invoice object
*/
fun getInvoice(
receiverUma: String,
invoiceUUID: String,
amount: Int,
receivingCurrency: InvoiceCurrency,
expiration: Int,
isSubjectToTravelRule: Boolean,
umaVersion: String,
commentCharsAllowed: Int? = null,
senderUma: String? = null,
invoiceLimit: Int? = null,
callback: String,
signature: ByteArray? = null,
kycStatus: KycStatus? = null,
requiredPayerData: CounterPartyDataOptions? = null
): Invoice {
return Invoice(
receiverUma = receiverUma,
invoiceUUID = invoiceUUID,
amount = amount,
receivingCurrency = receivingCurrency,
expiration = expiration,
isSubjectToTravelRule = isSubjectToTravelRule,
umaVersion = umaVersion,
commentCharsAllowed = commentCharsAllowed,
senderUma = senderUma,
invoiceLimit = invoiceLimit,
callback = callback,
signature = signature,
kycStatus = kycStatus,
requiredPayerData = requiredPayerData,
)
}
}

interface UmaInvoiceCreator {
Expand Down
30 changes: 30 additions & 0 deletions uma-sdk/src/commonMain/kotlin/me/uma/crypto/Bech32.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package me.uma.crypto

/**
* wrapper class for bech32 conversion functions
*/
object Bech32 {

fun encodeBech32(hrp: String, data: ByteArray): String {
return me.uma.crypto.internal.encodeBech32(
hrp, data.toByteList()
)
}

fun decodeBech32(bech32str: String): Bech32Data {
val data = me.uma.crypto.internal.decodeBech32(bech32str)
return Bech32Data(
data.hrp,
data.data.toByteArray()
)
}

private fun ByteArray.toByteList() = map { it.toUByte() }

private fun List<UByte>.toByteArray() = map { it.toByte() }.toByteArray()

data class Bech32Data(
val hrp: String,
val data: ByteArray
)
}
Loading
Loading