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
Merged

Mdavis/kt uma invoice #54

merged 11 commits into from
Aug 22, 2024

Conversation

matthappens
Copy link
Contributor

@matthappens matthappens commented Aug 14, 2024

Add UMA Invoice for kotlin, complete w/ bech32 encoding
https://linear.app/lightsparkdev/issue/LIG-6113/[uma-invoice]-kotlin-sdk-implementation

design:
This PR creates Invoice & InvoiceCurrency classes, which are serializable to TVL format
This is accomplished with custom serializers that convert the objects to ByteArrays, recursively encoding other TLV or byte codeable members.

Copy link
Contributor

@jklein24 jklein24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely seems to be heading down the right path!

Comment on lines 27 to 29
val encoded = serialFormat.encodeToString(invoiceCurrency)
println(encoded)
println("decoded object ${serialFormat.decodeFromString<InvoiceCurrency>(encoded)}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be good to pull out test vectors from some of the tests that @zhenlu wrote for other sdks just as a sanity check that they spit out the same thing.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/uma-universal-money-address/uma-go-sdk/blob/main/uma/test/protocol_test.go#L273

There's one trick part is that to serialize integers, different language might make a different size integer type so it won't fully align. (I had this problem in python)

uma-sdk/src/commonMain/kotlin/me/uma/utils/TLVUtils.kt Outdated Show resolved Hide resolved
}


fun ByteArray.getNumber(offset: Int): Int {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the offset here meant to be a byte offset or value index?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a starting index of the read value in the byte array. most of the methods for accessing byte arrays refer to this as offset, but here's it's being used as the starting index of the value being read . I'm fine switching the parameter names to "valueIndex" for readability if that's preferred

uma-sdk/src/commonMain/kotlin/me/uma/protocol/Invoice.kt Outdated Show resolved Hide resolved
fun toBech32(): String = Bech32.encode(Bech32.Encoding.BECH32, UMA_BECH32_PREFIX, this.toTLV())

companion object {
fun fromTLV(bytes: ByteArray): Invoice {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a non-optional field is not presented, we should throw an error here.

@@ -43,7 +43,7 @@ class UmaTests {
validateInvoice(invoice, result)
}

@Ignore("bech32 not complete")
// @Ignore("bech32 not complete")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove when you're ready.

.idea/other.xml Outdated
@@ -0,0 +1,252 @@
<?xml version="1.0" encoding="UTF-8"?>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll remove this file, assuming we don't want it in the repo

@matthappens matthappens merged commit 625a930 into main Aug 22, 2024
2 checks passed
@matthappens matthappens deleted the mdavis/kt-uma-invoice branch August 22, 2024 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants