diff --git a/sphinx-ffi/Cargo.toml b/sphinx-ffi/Cargo.toml index fa1918c..9cabc28 100644 --- a/sphinx-ffi/Cargo.toml +++ b/sphinx-ffi/Cargo.toml @@ -25,7 +25,7 @@ sphinx-signer = { path = "../signer", default-features = false, features = [ "no-native", ] } sphinx-glyph = { path = "../glyph", default-features = false } -sphinx = { git = "https://github.com/stakwork/sphinx", rev = "768a010bc4e7e5807dd679819faf39c94f7eeab6", features = [ +sphinx = { git = "https://github.com/stakwork/sphinx", rev = "611b0328fadef059abac68652db22fe2d765730e", features = [ "msg", "bindings", "macaroon", diff --git a/sphinx-ffi/src/auto.rs b/sphinx-ffi/src/auto.rs index 37560c5..eaccb1a 100644 --- a/sphinx-ffi/src/auto.rs +++ b/sphinx-ffi/src/auto.rs @@ -639,14 +639,23 @@ pub fn get_mutes(seed: String, unique_time: String, full_state: Vec) -> Resu .into()) } +pub fn decrypt_child_index(encrypted_child: String, push_key: String) -> Result { + Ok( + bindings::decode_encrypted_child_idx(&encrypted_child, &push_key) + .map_err(|e| SphinxError::SendFailed { r: e.to_string() })? + .into(), + ) +} + pub fn set_push_token( seed: String, unique_time: String, full_state: Vec, push_token: String, + push_key: String, ) -> Result { Ok( - bindings::set_push_token(&seed, &unique_time, &full_state, &push_token) + bindings::set_push_token(&seed, &unique_time, &full_state, &push_token, &push_key) .map_err(|e| SphinxError::SendFailed { r: e.to_string() })? .into(), ) diff --git a/sphinx-ffi/src/sphinxrs.swift b/sphinx-ffi/src/sphinxrs.swift index 9258d48..cb577c9 100644 --- a/sphinx-ffi/src/sphinxrs.swift +++ b/sphinx-ffi/src/sphinxrs.swift @@ -2455,14 +2455,25 @@ public func `getMutes`(`seed`: String, `uniqueTime`: String, `state`: Data) thro ) } -public func `setPushToken`(`seed`: String, `uniqueTime`: String, `state`: Data, `pushToken`: String) throws -> RunReturn { +public func `setPushToken`(`seed`: String, `uniqueTime`: String, `state`: Data, `pushToken`: String, `pushKey`: String) throws -> RunReturn { return try FfiConverterTypeRunReturn.lift( try rustCallWithError(FfiConverterTypeSphinxError.lift) { uniffi_sphinxrs_fn_func_set_push_token( FfiConverterString.lower(`seed`), FfiConverterString.lower(`uniqueTime`), FfiConverterData.lower(`state`), - FfiConverterString.lower(`pushToken`),$0) + FfiConverterString.lower(`pushToken`), + FfiConverterString.lower(`pushKey`),$0) +} + ) +} + +public func `decryptChildIndex`(`encryptedChild`: String, `pushKey`: String) throws -> UInt64 { + return try FfiConverterUInt64.lift( + try rustCallWithError(FfiConverterTypeSphinxError.lift) { + uniffi_sphinxrs_fn_func_decrypt_child_index( + FfiConverterString.lower(`encryptedChild`), + FfiConverterString.lower(`pushKey`),$0) } ) } @@ -2864,7 +2875,10 @@ private var initializationResult: InitializationResult { if (uniffi_sphinxrs_checksum_func_get_mutes() != 4885) { return InitializationResult.apiChecksumMismatch } - if (uniffi_sphinxrs_checksum_func_set_push_token() != 7668) { + if (uniffi_sphinxrs_checksum_func_set_push_token() != 52747) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_sphinxrs_checksum_func_decrypt_child_index() != 2032) { return InitializationResult.apiChecksumMismatch } if (uniffi_sphinxrs_checksum_func_get_msgs_counts() != 29743) { diff --git a/sphinx-ffi/src/sphinxrs.udl b/sphinx-ffi/src/sphinxrs.udl index fb16418..38da9b8 100644 --- a/sphinx-ffi/src/sphinxrs.udl +++ b/sphinx-ffi/src/sphinxrs.udl @@ -239,7 +239,9 @@ namespace sphinxrs { [Throws=SphinxError] RunReturn get_mutes(string seed, string unique_time, bytes state); [Throws=SphinxError] - RunReturn set_push_token(string seed, string unique_time, bytes state, string push_token); + RunReturn set_push_token(string seed, string unique_time, bytes state, string push_token, string push_key); + [Throws=SphinxError] + u64 decrypt_child_index(string encrypted_child, string push_key); [Throws=SphinxError] RunReturn get_msgs_counts(string seed, string unique_time, bytes state); [Throws=SphinxError] diff --git a/sphinx-ffi/src/sphinxrsFFI.h b/sphinx-ffi/src/sphinxrsFFI.h index 1c48f37..1d07f0f 100644 --- a/sphinx-ffi/src/sphinxrsFFI.h +++ b/sphinx-ffi/src/sphinxrsFFI.h @@ -60,6 +60,7 @@ typedef struct RustCallStatus { #endif // def UNIFFI_SHARED_H // Callbacks for UniFFI Futures +typedef void (*UniFfiFutureCallbackUInt64)(const void * _Nonnull, uint64_t, RustCallStatus); typedef void (*UniFfiFutureCallbackRustBuffer)(const void * _Nonnull, RustBuffer, RustCallStatus); // Scaffolding functions @@ -193,7 +194,9 @@ RustBuffer uniffi_sphinxrs_fn_func_mute(RustBuffer seed, RustBuffer unique_time, ); RustBuffer uniffi_sphinxrs_fn_func_get_mutes(RustBuffer seed, RustBuffer unique_time, RustBuffer state, RustCallStatus *_Nonnull out_status ); -RustBuffer uniffi_sphinxrs_fn_func_set_push_token(RustBuffer seed, RustBuffer unique_time, RustBuffer state, RustBuffer push_token, RustCallStatus *_Nonnull out_status +RustBuffer uniffi_sphinxrs_fn_func_set_push_token(RustBuffer seed, RustBuffer unique_time, RustBuffer state, RustBuffer push_token, RustBuffer push_key, RustCallStatus *_Nonnull out_status +); +uint64_t uniffi_sphinxrs_fn_func_decrypt_child_index(RustBuffer encrypted_child, RustBuffer push_key, RustCallStatus *_Nonnull out_status ); RustBuffer uniffi_sphinxrs_fn_func_get_msgs_counts(RustBuffer seed, RustBuffer unique_time, RustBuffer state, RustCallStatus *_Nonnull out_status ); @@ -430,6 +433,9 @@ uint16_t uniffi_sphinxrs_checksum_func_get_mutes(void ); uint16_t uniffi_sphinxrs_checksum_func_set_push_token(void +); +uint16_t uniffi_sphinxrs_checksum_func_decrypt_child_index(void + ); uint16_t uniffi_sphinxrs_checksum_func_get_msgs_counts(void diff --git a/sphinx-ffi/src/uniffi/sphinxrs/sphinxrs.kt b/sphinx-ffi/src/uniffi/sphinxrs/sphinxrs.kt index 718d9f8..d3fd18e 100644 --- a/sphinx-ffi/src/uniffi/sphinxrs/sphinxrs.kt +++ b/sphinx-ffi/src/uniffi/sphinxrs/sphinxrs.kt @@ -494,8 +494,10 @@ internal interface _UniFFILib : Library { ): RustBuffer.ByValue fun uniffi_sphinxrs_fn_func_get_mutes(`seed`: RustBuffer.ByValue,`uniqueTime`: RustBuffer.ByValue,`state`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus, ): RustBuffer.ByValue - fun uniffi_sphinxrs_fn_func_set_push_token(`seed`: RustBuffer.ByValue,`uniqueTime`: RustBuffer.ByValue,`state`: RustBuffer.ByValue,`pushToken`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus, + fun uniffi_sphinxrs_fn_func_set_push_token(`seed`: RustBuffer.ByValue,`uniqueTime`: RustBuffer.ByValue,`state`: RustBuffer.ByValue,`pushToken`: RustBuffer.ByValue,`pushKey`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus, ): RustBuffer.ByValue + fun uniffi_sphinxrs_fn_func_decrypt_child_index(`encryptedChild`: RustBuffer.ByValue,`pushKey`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus, + ): Long fun uniffi_sphinxrs_fn_func_get_msgs_counts(`seed`: RustBuffer.ByValue,`uniqueTime`: RustBuffer.ByValue,`state`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus, ): RustBuffer.ByValue fun uniffi_sphinxrs_fn_func_fetch_msgs_batch(`seed`: RustBuffer.ByValue,`uniqueTime`: RustBuffer.ByValue,`state`: RustBuffer.ByValue,`lastMsgIdx`: Long,`limit`: RustBuffer.ByValue,`reverse`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus, @@ -666,6 +668,8 @@ internal interface _UniFFILib : Library { ): Short fun uniffi_sphinxrs_checksum_func_set_push_token( ): Short + fun uniffi_sphinxrs_checksum_func_decrypt_child_index( + ): Short fun uniffi_sphinxrs_checksum_func_get_msgs_counts( ): Short fun uniffi_sphinxrs_checksum_func_fetch_msgs_batch( @@ -908,7 +912,10 @@ private fun uniffiCheckApiChecksums(lib: _UniFFILib) { if (lib.uniffi_sphinxrs_checksum_func_get_mutes() != 4885.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } - if (lib.uniffi_sphinxrs_checksum_func_set_push_token() != 7668.toShort()) { + if (lib.uniffi_sphinxrs_checksum_func_set_push_token() != 52747.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_sphinxrs_checksum_func_decrypt_child_index() != 2032.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } if (lib.uniffi_sphinxrs_checksum_func_get_msgs_counts() != 29743.toShort()) { @@ -2993,10 +3000,19 @@ fun `getMutes`(`seed`: String, `uniqueTime`: String, `state`: ByteArray): RunRet @Throws(SphinxException::class) -fun `setPushToken`(`seed`: String, `uniqueTime`: String, `state`: ByteArray, `pushToken`: String): RunReturn { +fun `setPushToken`(`seed`: String, `uniqueTime`: String, `state`: ByteArray, `pushToken`: String, `pushKey`: String): RunReturn { return FfiConverterTypeRunReturn.lift( rustCallWithError(SphinxException) { _status -> - _UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_set_push_token(FfiConverterString.lower(`seed`),FfiConverterString.lower(`uniqueTime`),FfiConverterByteArray.lower(`state`),FfiConverterString.lower(`pushToken`),_status) + _UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_set_push_token(FfiConverterString.lower(`seed`),FfiConverterString.lower(`uniqueTime`),FfiConverterByteArray.lower(`state`),FfiConverterString.lower(`pushToken`),FfiConverterString.lower(`pushKey`),_status) +}) +} + +@Throws(SphinxException::class) + +fun `decryptChildIndex`(`encryptedChild`: String, `pushKey`: String): ULong { + return FfiConverterULong.lift( + rustCallWithError(SphinxException) { _status -> + _UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_decrypt_child_index(FfiConverterString.lower(`encryptedChild`),FfiConverterString.lower(`pushKey`),_status) }) }