Skip to content

Commit

Permalink
push keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Evanfeenstra committed Aug 23, 2024
1 parent 43504ed commit f378b6a
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 11 deletions.
2 changes: 1 addition & 1 deletion sphinx-ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 10 additions & 1 deletion sphinx-ffi/src/auto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,14 +639,23 @@ pub fn get_mutes(seed: String, unique_time: String, full_state: Vec<u8>) -> Resu
.into())
}

pub fn decrypt_child_index(encrypted_child: String, push_key: String) -> Result<u64> {
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<u8>,
push_token: String,
push_key: String,
) -> Result<RunReturn> {
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(),
)
Expand Down
20 changes: 17 additions & 3 deletions sphinx-ffi/src/sphinxrs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
)
}
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion sphinx-ffi/src/sphinxrs.udl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
8 changes: 7 additions & 1 deletion sphinx-ffi/src/sphinxrsFFI.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
);
Expand Down Expand Up @@ -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

Expand Down
24 changes: 20 additions & 4 deletions sphinx-ffi/src/uniffi/sphinxrs/sphinxrs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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)
})
}

Expand Down

0 comments on commit f378b6a

Please sign in to comment.