Skip to content

Commit

Permalink
contact_for_encrypted_child_key, find_route
Browse files Browse the repository at this point in the history
  • Loading branch information
Evanfeenstra committed Aug 19, 2024
1 parent fe65b90 commit c9b11eb
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 1 deletion.
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 = "2de79ab96a4d0af2b5492ba5168444c217ff4d63", features = [
sphinx = { git = "https://github.com/stakwork/sphinx", rev = "d8c490d241b37ab0c47e725f9dae5d2e92f0ccfa", features = [
"msg",
"bindings",
"macaroon",
Expand Down
29 changes: 29 additions & 0 deletions sphinx-ffi/src/auto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,35 @@ pub fn signed_timestamp(seed: String, idx: u64, time: String, network: String) -
.into())
}

pub fn contact_for_encrypted_child_key(
seed: String,
unique_time: String,
full_state: Vec<u8>,
encrypted_child_idx: String,
) -> Result<String> {
Ok(bindings::contact_for_encrypted_child_key(
&seed,
&unique_time,
&full_state,
&encrypted_child_idx,
)
.map_err(|e| SphinxError::SendFailed { r: e.to_string() })?
.into())
}

pub fn find_route(
full_state: Vec<u8>,
to_pubkey: String,
to_route_hint: Option<String>,
amt_msat: u64,
) -> Result<String> {
Ok(
bindings::find_route(&full_state, &to_pubkey, to_route_hint, amt_msat)
.map_err(|e| SphinxError::SendFailed { r: e.to_string() })?
.into(),
)
}

impl From<bindings::Msg> for Msg {
fn from(rr: bindings::Msg) -> Self {
Msg {
Expand Down
30 changes: 30 additions & 0 deletions sphinx-ffi/src/sphinxrs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2642,6 +2642,30 @@ public func `idFromMacaroon`(`macaroon`: String) throws -> String {
)
}

public func `contactForEncryptedChildKey`(`seed`: String, `uniqueTime`: String, `state`: Data, `encryptedChildKey`: String) throws -> String {
return try FfiConverterString.lift(
try rustCallWithError(FfiConverterTypeSphinxError.lift) {
uniffi_sphinxrs_fn_func_contact_for_encrypted_child_key(
FfiConverterString.lower(`seed`),
FfiConverterString.lower(`uniqueTime`),
FfiConverterData.lower(`state`),
FfiConverterString.lower(`encryptedChildKey`),$0)
}
)
}

public func `findRoute`(`state`: Data, `toPubkey`: String, `routeHint`: String?, `amtMsat`: UInt64) throws -> String {
return try FfiConverterString.lift(
try rustCallWithError(FfiConverterTypeSphinxError.lift) {
uniffi_sphinxrs_fn_func_find_route(
FfiConverterData.lower(`state`),
FfiConverterString.lower(`toPubkey`),
FfiConverterOptionString.lower(`routeHint`),
FfiConverterUInt64.lower(`amtMsat`),$0)
}
)
}

private enum InitializationResult {
case ok
case contractVersionMismatch
Expand Down Expand Up @@ -2897,6 +2921,12 @@ private var initializationResult: InitializationResult {
if (uniffi_sphinxrs_checksum_func_id_from_macaroon() != 36424) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_sphinxrs_checksum_func_contact_for_encrypted_child_key() != 36351) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_sphinxrs_checksum_func_find_route() != 27285) {
return InitializationResult.apiChecksumMismatch
}

return InitializationResult.ok
}
Expand Down
4 changes: 4 additions & 0 deletions sphinx-ffi/src/sphinxrs.udl
Original file line number Diff line number Diff line change
Expand Up @@ -268,4 +268,8 @@ namespace sphinxrs {
RunReturn fetch_pings(string seed, string unique_time, bytes state);
[Throws=SphinxError]
string id_from_macaroon(string macaroon);
[Throws=SphinxError]
string contact_for_encrypted_child_key(string seed, string unique_time, bytes state, string encrypted_child_key);
[Throws=SphinxError]
string find_route(bytes state, string to_pubkey, string? route_hint, u64 amt_msat);
};
10 changes: 10 additions & 0 deletions sphinx-ffi/src/sphinxrsFFI.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ RustBuffer uniffi_sphinxrs_fn_func_fetch_pings(RustBuffer seed, RustBuffer uniqu
);
RustBuffer uniffi_sphinxrs_fn_func_id_from_macaroon(RustBuffer macaroon, RustCallStatus *_Nonnull out_status
);
RustBuffer uniffi_sphinxrs_fn_func_contact_for_encrypted_child_key(RustBuffer seed, RustBuffer unique_time, RustBuffer state, RustBuffer encrypted_child_key, RustCallStatus *_Nonnull out_status
);
RustBuffer uniffi_sphinxrs_fn_func_find_route(RustBuffer state, RustBuffer to_pubkey, RustBuffer route_hint, uint64_t amt_msat, RustCallStatus *_Nonnull out_status
);
RustBuffer ffi_sphinxrs_rustbuffer_alloc(int32_t size, RustCallStatus *_Nonnull out_status
);
RustBuffer ffi_sphinxrs_rustbuffer_from_bytes(ForeignBytes bytes, RustCallStatus *_Nonnull out_status
Expand Down Expand Up @@ -470,6 +474,12 @@ uint16_t uniffi_sphinxrs_checksum_func_fetch_pings(void
);
uint16_t uniffi_sphinxrs_checksum_func_id_from_macaroon(void

);
uint16_t uniffi_sphinxrs_checksum_func_contact_for_encrypted_child_key(void

);
uint16_t uniffi_sphinxrs_checksum_func_find_route(void

);
uint32_t ffi_sphinxrs_uniffi_contract_version(void

Expand Down
32 changes: 32 additions & 0 deletions sphinx-ffi/src/uniffi/sphinxrs/sphinxrs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,10 @@ internal interface _UniFFILib : Library {
): RustBuffer.ByValue
fun uniffi_sphinxrs_fn_func_id_from_macaroon(`macaroon`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
): RustBuffer.ByValue
fun uniffi_sphinxrs_fn_func_contact_for_encrypted_child_key(`seed`: RustBuffer.ByValue,`uniqueTime`: RustBuffer.ByValue,`state`: RustBuffer.ByValue,`encryptedChildKey`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
): RustBuffer.ByValue
fun uniffi_sphinxrs_fn_func_find_route(`state`: RustBuffer.ByValue,`toPubkey`: RustBuffer.ByValue,`routeHint`: RustBuffer.ByValue,`amtMsat`: Long,_uniffi_out_err: RustCallStatus,
): RustBuffer.ByValue
fun ffi_sphinxrs_rustbuffer_alloc(`size`: Int,_uniffi_out_err: RustCallStatus,
): RustBuffer.ByValue
fun ffi_sphinxrs_rustbuffer_from_bytes(`bytes`: ForeignBytes.ByValue,_uniffi_out_err: RustCallStatus,
Expand Down Expand Up @@ -692,6 +696,10 @@ internal interface _UniFFILib : Library {
): Short
fun uniffi_sphinxrs_checksum_func_id_from_macaroon(
): Short
fun uniffi_sphinxrs_checksum_func_contact_for_encrypted_child_key(
): Short
fun uniffi_sphinxrs_checksum_func_find_route(
): Short
fun ffi_sphinxrs_uniffi_contract_version(
): Int

Expand Down Expand Up @@ -949,6 +957,12 @@ private fun uniffiCheckApiChecksums(lib: _UniFFILib) {
if (lib.uniffi_sphinxrs_checksum_func_id_from_macaroon() != 36424.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_sphinxrs_checksum_func_contact_for_encrypted_child_key() != 36351.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_sphinxrs_checksum_func_find_route() != 27285.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
}

// Public interface members begin here.
Expand Down Expand Up @@ -3119,4 +3133,22 @@ fun `idFromMacaroon`(`macaroon`: String): String {
})
}

@Throws(SphinxException::class)

fun `contactForEncryptedChildKey`(`seed`: String, `uniqueTime`: String, `state`: ByteArray, `encryptedChildKey`: String): String {
return FfiConverterString.lift(
rustCallWithError(SphinxException) { _status ->
_UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_contact_for_encrypted_child_key(FfiConverterString.lower(`seed`),FfiConverterString.lower(`uniqueTime`),FfiConverterByteArray.lower(`state`),FfiConverterString.lower(`encryptedChildKey`),_status)
})
}

@Throws(SphinxException::class)

fun `findRoute`(`state`: ByteArray, `toPubkey`: String, `routeHint`: String?, `amtMsat`: ULong): String {
return FfiConverterString.lift(
rustCallWithError(SphinxException) { _status ->
_UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_find_route(FfiConverterByteArray.lower(`state`),FfiConverterString.lower(`toPubkey`),FfiConverterOptionalString.lower(`routeHint`),FfiConverterULong.lower(`amtMsat`),_status)
})
}


0 comments on commit c9b11eb

Please sign in to comment.