diff --git a/javatest/src/test/java/me/uma/javatest/UmaTest.java b/javatest/src/test/java/me/uma/javatest/UmaTest.java index f7526e0..fe370a8 100644 --- a/javatest/src/test/java/me/uma/javatest/UmaTest.java +++ b/javatest/src/test/java/me/uma/javatest/UmaTest.java @@ -2,6 +2,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -27,8 +28,8 @@ public class UmaTest { UmaProtocolHelper umaProtocolHelper = new UmaProtocolHelper(new InMemoryPublicKeyCache(), new TestUmaRequester()); - private static String PUBKEY_HEX = "02061e5634646e60cfbe2ca42e2be920b4deb749f0159ed7c428cdd8e3ea69c133"; - private static String PRIVKEY_HEX = "0e120a3c9ff18d295c6452cbb7ee3bb0f3d9c34f4db9e62293d2773f338a3b9d"; + private static String PUBKEY_HEX = "04f2998ab056897ddb91b5e6fad1e4bb6c4b7dda427409f667d0f4694b553e4feeeb08936c2993f7b931f6a3fa7e846f11165fae222de5e4a55c12def21a7c9fcf"; + private static String PRIVKEY_HEX = "10fbbee8f689b207bb22df2dfa27827ae9ae02e265980ea09ef5101ed5fb508f"; @Test @@ -49,13 +50,15 @@ public void testFetchPublicKeyFuture() throws Exception { public void testGetLnurlpRequest() throws Exception { String lnurlpUrl = umaProtocolHelper.getSignedLnurlpRequestUrl( privateKeyBytes(), - "$bob@vasp2.com", - "https://vasp.com", - true); + "$bob@uma-test.yourvasp.com", + /* senderVaspDomain */ "myvasp.com", + /* isSubjectToTravelRule */ true + ); assertNotNull(lnurlpUrl); System.out.println(lnurlpUrl); LnurlpRequest request = umaProtocolHelper.parseLnurlpRequest(lnurlpUrl); assertNotNull(request); + assertTrue(umaProtocolHelper.verifyUmaLnurlpQuerySignature(request, new PubKeyResponse(publicKeyBytes(), publicKeyBytes()))); System.out.println(request); } diff --git a/uma-sdk/src/commonMain/kotlin/me/uma/crypto/internal/UmaCrypto.kt b/uma-sdk/src/commonMain/kotlin/me/uma/crypto/internal/UmaCrypto.kt index d1674d0..19abdc0 100644 --- a/uma-sdk/src/commonMain/kotlin/me/uma/crypto/internal/UmaCrypto.kt +++ b/uma-sdk/src/commonMain/kotlin/me/uma/crypto/internal/UmaCrypto.kt @@ -46,7 +46,7 @@ open class RustBuffer : Structure() { companion object { internal fun alloc(size: Int = 0) = rustCall { status -> - _UniFFILib.INSTANCE.ffi_uma_crypto_d9b9_rustbuffer_alloc(size, status).also { + _UniFFILib.INSTANCE.ffi_uma_crypto_b9a_rustbuffer_alloc(size, status).also { if (it.data == null) { throw RuntimeException("RustBuffer.alloc() returned null data pointer (size=$size)") } @@ -55,7 +55,7 @@ open class RustBuffer : Structure() { internal fun free(buf: RustBuffer.ByValue) = rustCall { status -> - _UniFFILib.INSTANCE.ffi_uma_crypto_d9b9_rustbuffer_free(buf, status) + _UniFFILib.INSTANCE.ffi_uma_crypto_b9a_rustbuffer_free(buf, status) } } @@ -273,64 +273,64 @@ internal interface _UniFFILib : Library { } } - fun ffi_uma_crypto_d9b9_KeyPair_object_free( + fun ffi_uma_crypto_b9a_KeyPair_object_free( `ptr`: Pointer, _uniffi_out_err: RustCallStatus, ): Unit - fun uma_crypto_d9b9_KeyPair_get_public_key( + fun uma_crypto_b9a_KeyPair_get_public_key( `ptr`: Pointer, _uniffi_out_err: RustCallStatus, ): RustBuffer.ByValue - fun uma_crypto_d9b9_KeyPair_get_private_key( + fun uma_crypto_b9a_KeyPair_get_private_key( `ptr`: Pointer, _uniffi_out_err: RustCallStatus, ): RustBuffer.ByValue - fun uma_crypto_d9b9_sign_ecdsa( + fun uma_crypto_b9a_sign_ecdsa( `msg`: RustBuffer.ByValue, `privateKeyBytes`: RustBuffer.ByValue, _uniffi_out_err: RustCallStatus, ): RustBuffer.ByValue - fun uma_crypto_d9b9_verify_ecdsa( + fun uma_crypto_b9a_verify_ecdsa( `msg`: RustBuffer.ByValue, `signatureBytes`: RustBuffer.ByValue, `publicKeyBytes`: RustBuffer.ByValue, _uniffi_out_err: RustCallStatus, ): Byte - fun uma_crypto_d9b9_encrypt_ecies( + fun uma_crypto_b9a_encrypt_ecies( `msg`: RustBuffer.ByValue, `publicKeyBytes`: RustBuffer.ByValue, _uniffi_out_err: RustCallStatus, ): RustBuffer.ByValue - fun uma_crypto_d9b9_decrypt_ecies( + fun uma_crypto_b9a_decrypt_ecies( `cipherText`: RustBuffer.ByValue, `privateKeyBytes`: RustBuffer.ByValue, _uniffi_out_err: RustCallStatus, ): RustBuffer.ByValue - fun uma_crypto_d9b9_generate_keypair(_uniffi_out_err: RustCallStatus): Pointer + fun uma_crypto_b9a_generate_keypair(_uniffi_out_err: RustCallStatus): Pointer - fun ffi_uma_crypto_d9b9_rustbuffer_alloc( + fun ffi_uma_crypto_b9a_rustbuffer_alloc( `size`: Int, _uniffi_out_err: RustCallStatus, ): RustBuffer.ByValue - fun ffi_uma_crypto_d9b9_rustbuffer_from_bytes( + fun ffi_uma_crypto_b9a_rustbuffer_from_bytes( `bytes`: ForeignBytes.ByValue, _uniffi_out_err: RustCallStatus, ): RustBuffer.ByValue - fun ffi_uma_crypto_d9b9_rustbuffer_free( + fun ffi_uma_crypto_b9a_rustbuffer_free( `buf`: RustBuffer.ByValue, _uniffi_out_err: RustCallStatus, ): Unit - fun ffi_uma_crypto_d9b9_rustbuffer_reserve( + fun ffi_uma_crypto_b9a_rustbuffer_reserve( `buf`: RustBuffer.ByValue, `additional`: Int, _uniffi_out_err: RustCallStatus, @@ -444,6 +444,7 @@ public object FfiConverterString : FfiConverter { // helper method to execute a block and destroy the object at the end. interface Disposable { fun destroy() + companion object { fun destroy(vararg args: Any?) { args.filterIsInstance() @@ -614,14 +615,14 @@ class KeyPair( */ protected override fun freeRustArcPtr() { rustCall { status -> - _UniFFILib.INSTANCE.ffi_uma_crypto_d9b9_KeyPair_object_free(this.pointer, status) + _UniFFILib.INSTANCE.ffi_uma_crypto_b9a_KeyPair_object_free(this.pointer, status) } } override fun `getPublicKey`(): List = callWithPointer { rustCall { _status -> - _UniFFILib.INSTANCE.uma_crypto_d9b9_KeyPair_get_public_key(it, _status) + _UniFFILib.INSTANCE.uma_crypto_b9a_KeyPair_get_public_key(it, _status) } }.let { FfiConverterSequenceUByte.lift(it) @@ -630,7 +631,7 @@ class KeyPair( override fun `getPrivateKey`(): List = callWithPointer { rustCall { _status -> - _UniFFILib.INSTANCE.uma_crypto_d9b9_KeyPair_get_private_key(it, _status) + _UniFFILib.INSTANCE.uma_crypto_b9a_KeyPair_get_private_key(it, _status) } }.let { FfiConverterSequenceUByte.lift(it) @@ -667,8 +668,6 @@ sealed class CryptoException(message: String) : Exception(message) { // Flat enums carries a string error message, so no special implementation is necessary. class Secp256k1Exception(message: String) : CryptoException(message) - class RustSecp256k1Exception(message: String) : CryptoException(message) - companion object ErrorHandler : CallStatusErrorHandler { override fun lift(error_buf: RustBuffer.ByValue): CryptoException = FfiConverterTypeCryptoError.lift(error_buf) } @@ -678,7 +677,6 @@ public object FfiConverterTypeCryptoError : FfiConverterRustBuffer CryptoException.Secp256k1Exception(FfiConverterString.read(buf)) - 2 -> CryptoException.RustSecp256k1Exception(FfiConverterString.read(buf)) else -> throw RuntimeException("invalid error enum value, something is very wrong!!") } } @@ -696,10 +694,6 @@ public object FfiConverterTypeCryptoError : FfiConverterRustBuffer { - buf.putInt(2) - Unit - } }.let { /* this makes the `when` an expression, which ensures it is exhaustive */ } } } @@ -736,7 +730,7 @@ fun `signEcdsa`( ): List { return FfiConverterSequenceUByte.lift( rustCallWithError(CryptoException) { _status -> - _UniFFILib.INSTANCE.uma_crypto_d9b9_sign_ecdsa( + _UniFFILib.INSTANCE.uma_crypto_b9a_sign_ecdsa( FfiConverterSequenceUByte.lower(`msg`), FfiConverterSequenceUByte.lower(`privateKeyBytes`), _status, @@ -753,7 +747,7 @@ fun `verifyEcdsa`( ): Boolean { return FfiConverterBoolean.lift( rustCallWithError(CryptoException) { _status -> - _UniFFILib.INSTANCE.uma_crypto_d9b9_verify_ecdsa( + _UniFFILib.INSTANCE.uma_crypto_b9a_verify_ecdsa( FfiConverterSequenceUByte.lower(`msg`), FfiConverterSequenceUByte.lower(`signatureBytes`), FfiConverterSequenceUByte.lower(`publicKeyBytes`), @@ -770,7 +764,7 @@ fun `encryptEcies`( ): List { return FfiConverterSequenceUByte.lift( rustCallWithError(CryptoException) { _status -> - _UniFFILib.INSTANCE.uma_crypto_d9b9_encrypt_ecies( + _UniFFILib.INSTANCE.uma_crypto_b9a_encrypt_ecies( FfiConverterSequenceUByte.lower(`msg`), FfiConverterSequenceUByte.lower(`publicKeyBytes`), _status, @@ -786,7 +780,7 @@ fun `decryptEcies`( ): List { return FfiConverterSequenceUByte.lift( rustCallWithError(CryptoException) { _status -> - _UniFFILib.INSTANCE.uma_crypto_d9b9_decrypt_ecies( + _UniFFILib.INSTANCE.uma_crypto_b9a_decrypt_ecies( FfiConverterSequenceUByte.lower(`cipherText`), FfiConverterSequenceUByte.lower(`privateKeyBytes`), _status, @@ -799,7 +793,7 @@ fun `decryptEcies`( fun `generateKeypair`(): KeyPair { return FfiConverterTypeKeyPair.lift( rustCallWithError(CryptoException) { _status -> - _UniFFILib.INSTANCE.uma_crypto_d9b9_generate_keypair(_status) + _UniFFILib.INSTANCE.uma_crypto_b9a_generate_keypair(_status) }, ) } diff --git a/uma-sdk/src/jvmMain/resources/darwin-aarch64/libuniffi_uma_crypto.dylib b/uma-sdk/src/jvmMain/resources/darwin-aarch64/libuniffi_uma_crypto.dylib index d6aba97..6dede14 100755 Binary files a/uma-sdk/src/jvmMain/resources/darwin-aarch64/libuniffi_uma_crypto.dylib and b/uma-sdk/src/jvmMain/resources/darwin-aarch64/libuniffi_uma_crypto.dylib differ diff --git a/uma-sdk/src/jvmMain/resources/darwin-x86-64/libuniffi_uma_crypto.dylib b/uma-sdk/src/jvmMain/resources/darwin-x86-64/libuniffi_uma_crypto.dylib index 9e5750a..3998353 100755 Binary files a/uma-sdk/src/jvmMain/resources/darwin-x86-64/libuniffi_uma_crypto.dylib and b/uma-sdk/src/jvmMain/resources/darwin-x86-64/libuniffi_uma_crypto.dylib differ diff --git a/uma-sdk/src/jvmMain/resources/linux-aarch64/libuniffi_uma_crypto.so b/uma-sdk/src/jvmMain/resources/linux-aarch64/libuniffi_uma_crypto.so index 7e8b9d3..1450f7a 100755 Binary files a/uma-sdk/src/jvmMain/resources/linux-aarch64/libuniffi_uma_crypto.so and b/uma-sdk/src/jvmMain/resources/linux-aarch64/libuniffi_uma_crypto.so differ diff --git a/uma-sdk/src/jvmMain/resources/linux-x86-64/libuniffi_uma_crypto.so b/uma-sdk/src/jvmMain/resources/linux-x86-64/libuniffi_uma_crypto.so index 221a074..a9871a8 100755 Binary files a/uma-sdk/src/jvmMain/resources/linux-x86-64/libuniffi_uma_crypto.so and b/uma-sdk/src/jvmMain/resources/linux-x86-64/libuniffi_uma_crypto.so differ