From f18f6e46e7ed881485b95dab91b43328d929d12b Mon Sep 17 00:00:00 2001 From: Evan Feenstra Date: Mon, 18 Dec 2023 11:04:51 -0800 Subject: [PATCH] updated sphinx bindings --- sphinx-ffi/Cargo.toml | 18 +- sphinx-ffi/src/auto.rs | 189 +++++++ sphinx-ffi/src/lib.rs | 17 + sphinx-ffi/src/onion.rs | 32 +- sphinx-ffi/src/signer.rs | 18 +- sphinx-ffi/src/sphinxrs.swift | 543 ++++++++++++++++-- sphinx-ffi/src/sphinxrs.udl | 68 ++- sphinx-ffi/src/sphinxrsFFI.h | 72 ++- sphinx-ffi/src/uniffi/sphinxrs/sphinxrs.kt | 609 +++++++++++++++++++-- 9 files changed, 1436 insertions(+), 130 deletions(-) create mode 100644 sphinx-ffi/src/auto.rs diff --git a/sphinx-ffi/Cargo.toml b/sphinx-ffi/Cargo.toml index f70493f..5646681 100644 --- a/sphinx-ffi/Cargo.toml +++ b/sphinx-ffi/Cargo.toml @@ -20,9 +20,15 @@ lightning = { git = "https://github.com/Evanfeenstra/rust-lightning", rev = "3f5 [dependencies] sphinx-crypter = { path = "../crypter" } -sphinx-signer = { path = "../signer", default-features = false, features = ["persist", "no-native"] } +sphinx-signer = { path = "../signer", default-features = false, features = [ + "persist", + "no-native", +] } sphinx-glyph = { path = "../glyph", default-features = false } -sphinx = { git = "https://github.com/stakwork/sphinx", rev = "ee62c9305006a7e33eccd379a5749beff25e5eff", features = ["msg"] } +sphinx = { git = "https://github.com/stakwork/sphinx", rev = "a68d83b7a697403b52e9d26cfc2260627185942d", features = [ + "msg", + "bindings", +] } # sphinx = { path = "../../sphinx/sphinx" } uniffi = { version = "0.24.1", optional = true } hex = { version = "0.4.3", default-features = false } @@ -33,10 +39,10 @@ rmp-utils = { version = "0.1.0", path = "../rmp-utils" } uniffi = { version = "0.24.1", optional = true, features = ["build"] } [profile.release] -opt-level = 'z' # Optimize for size. -lto = true # Enable Link Time Optimization -codegen-units = 1 # Reduce number of codegen units to increase optimizations. -debug = true # Enable debug symbols. For example, we can use `dwarfdump` to check crash traces. +opt-level = 'z' # Optimize for size. +lto = true # Enable Link Time Optimization +codegen-units = 1 # Reduce number of codegen units to increase optimizations. +debug = true # Enable debug symbols. For example, we can use `dwarfdump` to check crash traces. [[bin]] name = "uniffi-bindgen" diff --git a/sphinx-ffi/src/auto.rs b/sphinx-ffi/src/auto.rs new file mode 100644 index 0000000..a50df28 --- /dev/null +++ b/sphinx-ffi/src/auto.rs @@ -0,0 +1,189 @@ +use crate::{Result, SphinxError}; +use sphinx::bindings; +use sphinx::serde_json; + +pub struct RunReturn { + pub topic_0: Option, + pub payload_0: Option>, + pub topic_1: Option, + pub payload_1: Option>, + pub topic_2: Option, + pub payload_2: Option>, + pub state_mp: Option>, + pub msg: Option, + pub msg_uuid: Option, + pub msg_index: Option, + pub msg_sender: Option, + pub new_balance: Option, + pub my_contact_info: Option, + pub sent_status: Option, + pub settled_status: Option, + pub error: Option, +} + +pub fn set_network(net: String) -> Result { + Ok(bindings::set_network(&net) + .map_err(|e| SphinxError::SetNetworkFailed { r: e.to_string() })? + .into()) +} + +pub fn set_blockheight(bh: u32) -> Result { + Ok(bindings::set_blockheight(bh) + .map_err(|e| SphinxError::SetBlockheightFailed { r: e.to_string() })? + .into()) +} + +pub fn add_contact( + seed: String, + unique_time: String, + full_state: Vec, + to_pubkey: String, + route_hint: String, + my_alias: String, + my_img: String, + amt_msat: u64, +) -> Result { + Ok(bindings::add_contact( + &seed, + &unique_time, + &full_state, + &to_pubkey, + &route_hint, + &my_alias, + &my_img_opt(&my_img), + amt_msat, + ) + .map_err(|e| SphinxError::AddContactFailed { r: e.to_string() })? + .into()) +} + +pub fn get_contact(full_state: Vec, contact_pubkey: String) -> Result { + let c = bindings::get_contact(&full_state, &contact_pubkey).map_err(|_| { + SphinxError::GetContactFailed { + r: format!("get_contact failed for pubkey: {}", &contact_pubkey), + } + })?; + let json = serde_json::to_string(&c).map_err(|_| SphinxError::GetContactFailed { + r: format!("get_contact serialization failed"), + })?; + Ok(json) +} + +pub fn list_contacts(full_state: Vec) -> Result { + let cs = bindings::list_contacts(&full_state).map_err(|_| SphinxError::GetContactFailed { + r: format!("list_contacts failed"), + })?; + let json = serde_json::to_string(&cs).map_err(|_| SphinxError::GetContactFailed { + r: format!("list_contacts serialization failed"), + })?; + Ok(json) +} + +pub fn get_subscription_topic( + seed: String, + unique_time: String, + full_state: Vec, +) -> Result { + Ok( + bindings::get_subscription_topic(&seed, &unique_time, &full_state) + .map_err(|e| SphinxError::HandleFailed { r: e.to_string() })?, + ) +} + +pub fn initial_setup(seed: String, unique_time: String, full_state: Vec) -> Result { + Ok(bindings::initial_setup(&seed, &unique_time, &full_state) + .map_err(|e| SphinxError::HandleFailed { r: e.to_string() })? + .into()) +} + +pub fn fetch_msgs( + seed: String, + unique_time: String, + full_state: Vec, + last_msg_idx: u64, + limit: Option, +) -> Result { + Ok( + bindings::fetch_msgs(&seed, &unique_time, &full_state, last_msg_idx, limit) + .map_err(|e| SphinxError::FetchMsgsFailed { r: e.to_string() })? + .into(), + ) +} + +pub fn handle( + topic: String, + payload: Vec, + seed: String, + unique_time: String, + full_state: Vec, + my_alias: String, + my_img: String, +) -> Result { + Ok(bindings::handle( + &topic, + &payload, + &seed, + &unique_time, + &full_state, + &my_alias, + &my_img_opt(&my_img), + ) + .map_err(|e| SphinxError::HandleFailed { r: e.to_string() })? + .into()) +} + +pub fn send( + seed: String, + unique_time: String, + to: String, + msg_type: u8, + msg_json: String, + full_state: Vec, + my_alias: String, + my_img: String, + amt_msat: u64, +) -> Result { + Ok(bindings::send( + &seed, + &unique_time, + &to, + msg_type, + &msg_json, + &full_state, + &my_alias, + &my_img_opt(&my_img), + amt_msat, + ) + .map_err(|e| SphinxError::SendFailed { r: e.to_string() })? + .into()) +} + +fn my_img_opt(my_img: &str) -> Option<&str> { + match my_img { + "" => None, + _ => Some(my_img), + } +} + +impl From for RunReturn { + fn from(rr: bindings::RunReturn) -> Self { + RunReturn { + topic_0: rr.topic_0, + payload_0: rr.payload_0, + topic_1: rr.topic_1, + payload_1: rr.payload_1, + topic_2: rr.topic_2, + payload_2: rr.payload_2, + state_mp: rr.state_mp, + msg: rr.msg, + msg_uuid: rr.msg_uuid, + msg_index: rr.msg_index, + msg_sender: rr.msg_sender, + new_balance: rr.new_balance, + my_contact_info: rr.my_contact_info, + sent_status: rr.sent_status, + settled_status: rr.settled_status, + error: rr.error, + } + } +} diff --git a/sphinx-ffi/src/lib.rs b/sphinx-ffi/src/lib.rs index 6dd4288..7fed551 100644 --- a/sphinx-ffi/src/lib.rs +++ b/sphinx-ffi/src/lib.rs @@ -1,3 +1,4 @@ +mod auto; mod control; mod onion; mod parse; @@ -9,6 +10,8 @@ pub use signer::*; pub use onion::*; +pub use auto::*; + use sphinx_crypter::chacha::{decrypt as chacha_decrypt, encrypt as chacha_encrypt}; use sphinx_crypter::ecdh::derive_shared_secret_from_slice; use sphinx_crypter::secp256k1::{PublicKey, Secp256k1, SecretKey}; @@ -62,6 +65,20 @@ pub enum SphinxError { BadChildIndex { r: String }, #[error("Bad Msg: {r}")] BadMsg { r: String }, + #[error("AddContactFailed: {r}")] + AddContactFailed { r: String }, + #[error("GetContactFailed: {r}")] + GetContactFailed { r: String }, + #[error("HandleFailed: {r}")] + HandleFailed { r: String }, + #[error("FetchMsgsFailed: {r}")] + FetchMsgsFailed { r: String }, + #[error("SendFailed: {r}")] + SendFailed { r: String }, + #[error("SetNetworkFailed: {r}")] + SetNetworkFailed { r: String }, + #[error("SetBlockheightFailed: {r}")] + SetBlockheightFailed { r: String }, } pub fn pubkey_from_secret_key(my_secret_key: String) -> Result { diff --git a/sphinx-ffi/src/onion.rs b/sphinx-ffi/src/onion.rs index 728be54..38fdbbb 100644 --- a/sphinx-ffi/src/onion.rs +++ b/sphinx-ffi/src/onion.rs @@ -24,7 +24,7 @@ pub fn root_sign_ms(seed: String, time: String, net: String) -> Result { Ok(hex::encode(sig)) } -pub fn sign_ms(seed: String, idx: u32, time: String, network: String) -> Result { +pub fn sign_ms(seed: String, idx: u64, time: String, network: String) -> Result { let idx = idx_to_idx(idx)?; let km = make_keys_manager(&seed, idx, &time, &network)?; let sig = sphinx::sig::sign_message(time.as_bytes(), &km.get_node_secret()).map_err(|_| { @@ -37,7 +37,7 @@ pub fn sign_ms(seed: String, idx: u32, time: String, network: String) -> Result< pub fn sign_bytes( seed: String, - idx: u32, + idx: u64, time: String, network: String, msg: Vec, @@ -52,7 +52,7 @@ pub fn sign_bytes( Ok(hex::encode(sig)) } -pub fn pubkey_from_seed(seed: String, idx: u32, time: String, network: String) -> Result { +pub fn pubkey_from_seed(seed: String, idx: u64, time: String, network: String) -> Result { let idx = idx_to_idx(idx)?; let km = make_keys_manager(&seed, idx, &time, &network)?; let pubkey = km.get_node_pubkey(); @@ -67,7 +67,7 @@ fn create_onion_inner(km: &MyKeysManager, hops: String, payload: Vec) -> Res pub fn create_onion( seed: String, - idx: u32, + idx: u64, time: String, network: String, hops: String, @@ -81,7 +81,7 @@ pub fn create_onion( pub fn create_onion_msg( seed: String, - idx: u32, + idx: u64, time: String, network: String, hops: String, @@ -97,7 +97,7 @@ pub fn create_onion_msg( pub fn peel_onion( seed: String, - idx: u32, + idx: u64, time: String, network: String, payload: Vec, @@ -109,7 +109,7 @@ pub fn peel_onion( pub fn peel_onion_msg( seed: String, - idx: u32, + idx: u64, time: String, network: String, payload: Vec, @@ -117,7 +117,7 @@ pub fn peel_onion_msg( let idx = idx_to_idx(idx)?; let km = make_keys_manager(&seed, idx, &time, &network)?; let bytes = run_peel_received_onion_to_bytes(&km, &payload)?; - let msg = sphinx::msg::parse_sphinx_msg_to_json(&bytes, None) + let msg = sphinx::msg::parse_sphinx_msg_to_json(&bytes, 0) .map_err(|e| SphinxError::BadMsg { r: e.to_string() })?; Ok(msg) } @@ -140,7 +140,7 @@ pub fn create_keysend_inner( pub fn create_keysend( seed: String, - idx: u32, + idx: u64, time: String, network: String, hops: String, @@ -158,7 +158,7 @@ pub fn create_keysend( pub fn create_keysend_msg( seed: String, - idx: u32, + idx: u64, time: String, network: String, hops: String, @@ -178,7 +178,7 @@ pub fn create_keysend_msg( pub fn peel_payment( seed: String, - idx: u32, + idx: u64, time: String, network: String, payload: Vec, @@ -200,7 +200,7 @@ pub fn peel_payment( pub fn peel_payment_msg( seed: String, - idx: u32, + idx: u64, time: String, network: String, payload: Vec, @@ -213,12 +213,12 @@ pub fn peel_payment_msg( let payment_hash = parse_hash(&rhash)?; let (_amt, _preimage, bytes) = run_peel_received_payment_to_bytes(&km, &payload, payment_hash, cur_height, cltv_expiry)?; - let msg = sphinx::msg::parse_sphinx_msg_to_json(&bytes, None) + let msg = sphinx::msg::parse_sphinx_msg_to_json(&bytes, 0) .map_err(|e| SphinxError::BadMsg { r: e.to_string() })?; Ok(msg) } -fn idx_to_idx(idx: u32) -> Result> { +fn idx_to_idx(idx: u64) -> Result> { Ok(Some(idx.try_into().map_err(|_| { SphinxError::BadChildIndex { r: "infallible".to_string(), @@ -228,7 +228,7 @@ fn idx_to_idx(idx: u32) -> Result> { fn make_keys_manager( seed: &str, - idx: Option, + idx: Option, time: &str, network: &str, ) -> Result { @@ -237,7 +237,7 @@ fn make_keys_manager( let net = Network::from_str(network).map_err(|_| SphinxError::BadArgs { r: "invalid network".to_string(), })?; - let mut mkm = make_signer(&seed, idx, ts, net); + let mkm = make_signer(&seed, idx, ts, net); Ok(mkm) } diff --git a/sphinx-ffi/src/signer.rs b/sphinx-ffi/src/signer.rs index dcc9d06..38aceee 100644 --- a/sphinx-ffi/src/signer.rs +++ b/sphinx-ffi/src/signer.rs @@ -248,14 +248,14 @@ impl VlsResponse { } } -fn run_init_1_manual( +fn _run_init_1_manual( args_string: String, state_mp: Vec, msg1: Vec, vel: Option>, ) -> Result { let args = args_from_json(&args_string)?; - let state = state_from_mp(&state_mp)?; + let state = _state_from_mp(&state_mp)?; let velocity = vel_from_mp(vel)?; let ret = mobile::run_init_1(args, state, &msg1, velocity).map_err(|e| SphinxError::InitFailed { @@ -264,7 +264,7 @@ fn run_init_1_manual( Ok(ret.0) } -fn run_init_2_manual( +fn _run_init_2_manual( args_string: String, state_mp: Vec, msg1: Vec, @@ -272,7 +272,7 @@ fn run_init_2_manual( vel: Option>, ) -> Result { let args = args_from_json(&args_string)?; - let state = state_from_mp(&state_mp)?; + let state = _state_from_mp(&state_mp)?; let velocity = vel_from_mp(vel)?; let ret = mobile::run_init_2(args, state, &msg1, &msg2, velocity).map_err(|e| { SphinxError::InitFailed { @@ -282,7 +282,7 @@ fn run_init_2_manual( Ok(ret.0) } -fn run_vls_manual( +fn _run_vls_manual( args_string: String, state_mp: Vec, msg1: Vec, @@ -292,7 +292,7 @@ fn run_vls_manual( vel: Option>, ) -> Result { let args = args_from_json(&args_string)?; - let state = state_from_mp(&state_mp)?; + let state = _state_from_mp(&state_mp)?; let velocity = vel_from_mp(vel)?; let ret = mobile::run_vls(args, state, &msg1, &msg2, &vls_msg, sequence, velocity); Ok(ret.map_err(|e| SphinxError::VlsFailed { @@ -300,7 +300,7 @@ fn run_vls_manual( })?) } -fn run_lss_manual( +fn _run_lss_manual( args_string: String, state_mp: Vec, msg1: Vec, @@ -310,7 +310,7 @@ fn run_lss_manual( prev_lss: Vec, ) -> Result { let args = args_from_json(&args_string)?; - let state = state_from_mp(&state_mp)?; + let state = _state_from_mp(&state_mp)?; let ret = mobile::run_lss(args, state, &msg1, &msg2, &lss_msg, &prev_vls, &prev_lss).map_err( |e| SphinxError::LssFailed { r: format!("{:?}", e), @@ -319,7 +319,7 @@ fn run_lss_manual( Ok(ret) } -fn state_from_mp(state_mp: &[u8]) -> Result { +fn _state_from_mp(state_mp: &[u8]) -> Result { let state: mobile::State = rmp_utils::deserialize_state_map(state_mp).map_err(|e| SphinxError::BadState { r: format!("{:?}", e), diff --git a/sphinx-ffi/src/sphinxrs.swift b/sphinx-ffi/src/sphinxrs.swift index f2130c1..4bfe8fd 100644 --- a/sphinx-ffi/src/sphinxrs.swift +++ b/sphinx-ffi/src/sphinxrs.swift @@ -293,6 +293,19 @@ private func uniffiCheckCallStatus( // Public interface members begin here. +fileprivate struct FfiConverterUInt8: FfiConverterPrimitive { + typealias FfiType = UInt8 + typealias SwiftType = UInt8 + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UInt8 { + return try lift(readInt(&buf)) + } + + public static func write(_ value: UInt8, into buf: inout [UInt8]) { + writeInt(&buf, lower(value)) + } +} + fileprivate struct FfiConverterUInt16: FfiConverterPrimitive { typealias FfiType = UInt16 typealias SwiftType = UInt16 @@ -441,6 +454,173 @@ public func FfiConverterTypeKeys_lower(_ value: Keys) -> RustBuffer { } +public struct RunReturn { + public var `topic0`: String? + public var `payload0`: Data? + public var `topic1`: String? + public var `payload1`: Data? + public var `topic2`: String? + public var `payload2`: Data? + public var `stateMp`: Data? + public var `msg`: String? + public var `msgUuid`: String? + public var `msgIndex`: String? + public var `msgSender`: String? + public var `newBalance`: UInt64? + public var `myContactInfo`: String? + public var `sentStatus`: String? + public var `settledStatus`: String? + public var `error`: String? + + // Default memberwise initializers are never public by default, so we + // declare one manually. + public init(`topic0`: String?, `payload0`: Data?, `topic1`: String?, `payload1`: Data?, `topic2`: String?, `payload2`: Data?, `stateMp`: Data?, `msg`: String?, `msgUuid`: String?, `msgIndex`: String?, `msgSender`: String?, `newBalance`: UInt64?, `myContactInfo`: String?, `sentStatus`: String?, `settledStatus`: String?, `error`: String?) { + self.`topic0` = `topic0` + self.`payload0` = `payload0` + self.`topic1` = `topic1` + self.`payload1` = `payload1` + self.`topic2` = `topic2` + self.`payload2` = `payload2` + self.`stateMp` = `stateMp` + self.`msg` = `msg` + self.`msgUuid` = `msgUuid` + self.`msgIndex` = `msgIndex` + self.`msgSender` = `msgSender` + self.`newBalance` = `newBalance` + self.`myContactInfo` = `myContactInfo` + self.`sentStatus` = `sentStatus` + self.`settledStatus` = `settledStatus` + self.`error` = `error` + } +} + + +extension RunReturn: Equatable, Hashable { + public static func ==(lhs: RunReturn, rhs: RunReturn) -> Bool { + if lhs.`topic0` != rhs.`topic0` { + return false + } + if lhs.`payload0` != rhs.`payload0` { + return false + } + if lhs.`topic1` != rhs.`topic1` { + return false + } + if lhs.`payload1` != rhs.`payload1` { + return false + } + if lhs.`topic2` != rhs.`topic2` { + return false + } + if lhs.`payload2` != rhs.`payload2` { + return false + } + if lhs.`stateMp` != rhs.`stateMp` { + return false + } + if lhs.`msg` != rhs.`msg` { + return false + } + if lhs.`msgUuid` != rhs.`msgUuid` { + return false + } + if lhs.`msgIndex` != rhs.`msgIndex` { + return false + } + if lhs.`msgSender` != rhs.`msgSender` { + return false + } + if lhs.`newBalance` != rhs.`newBalance` { + return false + } + if lhs.`myContactInfo` != rhs.`myContactInfo` { + return false + } + if lhs.`sentStatus` != rhs.`sentStatus` { + return false + } + if lhs.`settledStatus` != rhs.`settledStatus` { + return false + } + if lhs.`error` != rhs.`error` { + return false + } + return true + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(`topic0`) + hasher.combine(`payload0`) + hasher.combine(`topic1`) + hasher.combine(`payload1`) + hasher.combine(`topic2`) + hasher.combine(`payload2`) + hasher.combine(`stateMp`) + hasher.combine(`msg`) + hasher.combine(`msgUuid`) + hasher.combine(`msgIndex`) + hasher.combine(`msgSender`) + hasher.combine(`newBalance`) + hasher.combine(`myContactInfo`) + hasher.combine(`sentStatus`) + hasher.combine(`settledStatus`) + hasher.combine(`error`) + } +} + + +public struct FfiConverterTypeRunReturn: FfiConverterRustBuffer { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> RunReturn { + return try RunReturn( + `topic0`: FfiConverterOptionString.read(from: &buf), + `payload0`: FfiConverterOptionData.read(from: &buf), + `topic1`: FfiConverterOptionString.read(from: &buf), + `payload1`: FfiConverterOptionData.read(from: &buf), + `topic2`: FfiConverterOptionString.read(from: &buf), + `payload2`: FfiConverterOptionData.read(from: &buf), + `stateMp`: FfiConverterOptionData.read(from: &buf), + `msg`: FfiConverterOptionString.read(from: &buf), + `msgUuid`: FfiConverterOptionString.read(from: &buf), + `msgIndex`: FfiConverterOptionString.read(from: &buf), + `msgSender`: FfiConverterOptionString.read(from: &buf), + `newBalance`: FfiConverterOptionUInt64.read(from: &buf), + `myContactInfo`: FfiConverterOptionString.read(from: &buf), + `sentStatus`: FfiConverterOptionString.read(from: &buf), + `settledStatus`: FfiConverterOptionString.read(from: &buf), + `error`: FfiConverterOptionString.read(from: &buf) + ) + } + + public static func write(_ value: RunReturn, into buf: inout [UInt8]) { + FfiConverterOptionString.write(value.`topic0`, into: &buf) + FfiConverterOptionData.write(value.`payload0`, into: &buf) + FfiConverterOptionString.write(value.`topic1`, into: &buf) + FfiConverterOptionData.write(value.`payload1`, into: &buf) + FfiConverterOptionString.write(value.`topic2`, into: &buf) + FfiConverterOptionData.write(value.`payload2`, into: &buf) + FfiConverterOptionData.write(value.`stateMp`, into: &buf) + FfiConverterOptionString.write(value.`msg`, into: &buf) + FfiConverterOptionString.write(value.`msgUuid`, into: &buf) + FfiConverterOptionString.write(value.`msgIndex`, into: &buf) + FfiConverterOptionString.write(value.`msgSender`, into: &buf) + FfiConverterOptionUInt64.write(value.`newBalance`, into: &buf) + FfiConverterOptionString.write(value.`myContactInfo`, into: &buf) + FfiConverterOptionString.write(value.`sentStatus`, into: &buf) + FfiConverterOptionString.write(value.`settledStatus`, into: &buf) + FfiConverterOptionString.write(value.`error`, into: &buf) + } +} + + +public func FfiConverterTypeRunReturn_lift(_ buf: RustBuffer) throws -> RunReturn { + return try FfiConverterTypeRunReturn.lift(buf) +} + +public func FfiConverterTypeRunReturn_lower(_ value: RunReturn) -> RustBuffer { + return FfiConverterTypeRunReturn.lower(value) +} + + public struct VlsResponse { public var `topic`: String public var `bytes`: Data @@ -543,6 +723,13 @@ public enum SphinxError { case VlsFailed(`r`: String) case BadChildIndex(`r`: String) case BadMsg(`r`: String) + case AddContactFailed(`r`: String) + case GetContactFailed(`r`: String) + case HandleFailed(`r`: String) + case FetchMsgsFailed(`r`: String) + case SendFailed(`r`: String) + case SetNetworkFailed(`r`: String) + case SetBlockheightFailed(`r`: String) fileprivate static func uniffiErrorHandler(_ error: RustBuffer) throws -> Error { return try FfiConverterTypeSphinxError.lift(error) @@ -620,6 +807,27 @@ public struct FfiConverterTypeSphinxError: FfiConverterRustBuffer { case 20: return .BadMsg( `r`: try FfiConverterString.read(from: &buf) ) + case 21: return .AddContactFailed( + `r`: try FfiConverterString.read(from: &buf) + ) + case 22: return .GetContactFailed( + `r`: try FfiConverterString.read(from: &buf) + ) + case 23: return .HandleFailed( + `r`: try FfiConverterString.read(from: &buf) + ) + case 24: return .FetchMsgsFailed( + `r`: try FfiConverterString.read(from: &buf) + ) + case 25: return .SendFailed( + `r`: try FfiConverterString.read(from: &buf) + ) + case 26: return .SetNetworkFailed( + `r`: try FfiConverterString.read(from: &buf) + ) + case 27: return .SetBlockheightFailed( + `r`: try FfiConverterString.read(from: &buf) + ) default: throw UniffiInternalError.unexpectedEnumCase } @@ -731,6 +939,41 @@ public struct FfiConverterTypeSphinxError: FfiConverterRustBuffer { writeInt(&buf, Int32(20)) FfiConverterString.write(`r`, into: &buf) + + case let .AddContactFailed(`r`): + writeInt(&buf, Int32(21)) + FfiConverterString.write(`r`, into: &buf) + + + case let .GetContactFailed(`r`): + writeInt(&buf, Int32(22)) + FfiConverterString.write(`r`, into: &buf) + + + case let .HandleFailed(`r`): + writeInt(&buf, Int32(23)) + FfiConverterString.write(`r`, into: &buf) + + + case let .FetchMsgsFailed(`r`): + writeInt(&buf, Int32(24)) + FfiConverterString.write(`r`, into: &buf) + + + case let .SendFailed(`r`): + writeInt(&buf, Int32(25)) + FfiConverterString.write(`r`, into: &buf) + + + case let .SetNetworkFailed(`r`): + writeInt(&buf, Int32(26)) + FfiConverterString.write(`r`, into: &buf) + + + case let .SetBlockheightFailed(`r`): + writeInt(&buf, Int32(27)) + FfiConverterString.write(`r`, into: &buf) + } } } @@ -761,6 +1004,90 @@ fileprivate struct FfiConverterOptionUInt16: FfiConverterRustBuffer { } } +fileprivate struct FfiConverterOptionUInt32: FfiConverterRustBuffer { + typealias SwiftType = UInt32? + + public static func write(_ value: SwiftType, into buf: inout [UInt8]) { + guard let value = value else { + writeInt(&buf, Int8(0)) + return + } + writeInt(&buf, Int8(1)) + FfiConverterUInt32.write(value, into: &buf) + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { + switch try readInt(&buf) as Int8 { + case 0: return nil + case 1: return try FfiConverterUInt32.read(from: &buf) + default: throw UniffiInternalError.unexpectedOptionalTag + } + } +} + +fileprivate struct FfiConverterOptionUInt64: FfiConverterRustBuffer { + typealias SwiftType = UInt64? + + public static func write(_ value: SwiftType, into buf: inout [UInt8]) { + guard let value = value else { + writeInt(&buf, Int8(0)) + return + } + writeInt(&buf, Int8(1)) + FfiConverterUInt64.write(value, into: &buf) + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { + switch try readInt(&buf) as Int8 { + case 0: return nil + case 1: return try FfiConverterUInt64.read(from: &buf) + default: throw UniffiInternalError.unexpectedOptionalTag + } + } +} + +fileprivate struct FfiConverterOptionString: FfiConverterRustBuffer { + typealias SwiftType = String? + + public static func write(_ value: SwiftType, into buf: inout [UInt8]) { + guard let value = value else { + writeInt(&buf, Int8(0)) + return + } + writeInt(&buf, Int8(1)) + FfiConverterString.write(value, into: &buf) + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { + switch try readInt(&buf) as Int8 { + case 0: return nil + case 1: return try FfiConverterString.read(from: &buf) + default: throw UniffiInternalError.unexpectedOptionalTag + } + } +} + +fileprivate struct FfiConverterOptionData: FfiConverterRustBuffer { + typealias SwiftType = Data? + + public static func write(_ value: SwiftType, into buf: inout [UInt8]) { + guard let value = value else { + writeInt(&buf, Int8(0)) + return + } + writeInt(&buf, Int8(1)) + FfiConverterData.write(value, into: &buf) + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { + switch try readInt(&buf) as Int8 { + case 0: return nil + case 1: return try FfiConverterData.read(from: &buf) + default: throw UniffiInternalError.unexpectedOptionalTag + } + } +} + public func `pubkeyFromSecretKey`(`mySecretKey`: String) throws -> String { return try FfiConverterString.lift( try rustCallWithError(FfiConverterTypeSphinxError.lift) { @@ -899,12 +1226,12 @@ public func `sha256`(`msg`: Data) -> String { ) } -public func `createOnion`(`seed`: String, `idx`: UInt32, `time`: String, `network`: String, `hops`: String, `payload`: Data) throws -> Data { +public func `createOnion`(`seed`: String, `idx`: UInt64, `time`: String, `network`: String, `hops`: String, `payload`: Data) throws -> Data { return try FfiConverterData.lift( try rustCallWithError(FfiConverterTypeSphinxError.lift) { uniffi_sphinxrs_fn_func_create_onion( FfiConverterString.lower(`seed`), - FfiConverterUInt32.lower(`idx`), + FfiConverterUInt64.lower(`idx`), FfiConverterString.lower(`time`), FfiConverterString.lower(`network`), FfiConverterString.lower(`hops`), @@ -913,12 +1240,12 @@ public func `createOnion`(`seed`: String, `idx`: UInt32, `time`: String, `networ ) } -public func `createOnionMsg`(`seed`: String, `idx`: UInt32, `time`: String, `network`: String, `hops`: String, `json`: String) throws -> Data { +public func `createOnionMsg`(`seed`: String, `idx`: UInt64, `time`: String, `network`: String, `hops`: String, `json`: String) throws -> Data { return try FfiConverterData.lift( try rustCallWithError(FfiConverterTypeSphinxError.lift) { uniffi_sphinxrs_fn_func_create_onion_msg( FfiConverterString.lower(`seed`), - FfiConverterUInt32.lower(`idx`), + FfiConverterUInt64.lower(`idx`), FfiConverterString.lower(`time`), FfiConverterString.lower(`network`), FfiConverterString.lower(`hops`), @@ -927,12 +1254,12 @@ public func `createOnionMsg`(`seed`: String, `idx`: UInt32, `time`: String, `net ) } -public func `createKeysend`(`seed`: String, `idx`: UInt32, `time`: String, `network`: String, `hops`: String, `msat`: UInt64, `rhash`: String, `payload`: Data, `currHeight`: UInt32, `preimage`: String) throws -> Data { +public func `createKeysend`(`seed`: String, `idx`: UInt64, `time`: String, `network`: String, `hops`: String, `msat`: UInt64, `rhash`: String, `payload`: Data, `currHeight`: UInt32, `preimage`: String) throws -> Data { return try FfiConverterData.lift( try rustCallWithError(FfiConverterTypeSphinxError.lift) { uniffi_sphinxrs_fn_func_create_keysend( FfiConverterString.lower(`seed`), - FfiConverterUInt32.lower(`idx`), + FfiConverterUInt64.lower(`idx`), FfiConverterString.lower(`time`), FfiConverterString.lower(`network`), FfiConverterString.lower(`hops`), @@ -945,12 +1272,12 @@ public func `createKeysend`(`seed`: String, `idx`: UInt32, `time`: String, `netw ) } -public func `createKeysendMsg`(`seed`: String, `idx`: UInt32, `time`: String, `network`: String, `hops`: String, `msat`: UInt64, `rhash`: String, `msgJson`: String, `currHeight`: UInt32, `preimage`: String) throws -> Data { +public func `createKeysendMsg`(`seed`: String, `idx`: UInt64, `time`: String, `network`: String, `hops`: String, `msat`: UInt64, `rhash`: String, `msgJson`: String, `currHeight`: UInt32, `preimage`: String) throws -> Data { return try FfiConverterData.lift( try rustCallWithError(FfiConverterTypeSphinxError.lift) { uniffi_sphinxrs_fn_func_create_keysend_msg( FfiConverterString.lower(`seed`), - FfiConverterUInt32.lower(`idx`), + FfiConverterUInt64.lower(`idx`), FfiConverterString.lower(`time`), FfiConverterString.lower(`network`), FfiConverterString.lower(`hops`), @@ -963,12 +1290,12 @@ public func `createKeysendMsg`(`seed`: String, `idx`: UInt32, `time`: String, `n ) } -public func `peelOnion`(`seed`: String, `idx`: UInt32, `time`: String, `network`: String, `payload`: Data) throws -> Data { +public func `peelOnion`(`seed`: String, `idx`: UInt64, `time`: String, `network`: String, `payload`: Data) throws -> Data { return try FfiConverterData.lift( try rustCallWithError(FfiConverterTypeSphinxError.lift) { uniffi_sphinxrs_fn_func_peel_onion( FfiConverterString.lower(`seed`), - FfiConverterUInt32.lower(`idx`), + FfiConverterUInt64.lower(`idx`), FfiConverterString.lower(`time`), FfiConverterString.lower(`network`), FfiConverterData.lower(`payload`),$0) @@ -976,12 +1303,12 @@ public func `peelOnion`(`seed`: String, `idx`: UInt32, `time`: String, `network` ) } -public func `peelOnionMsg`(`seed`: String, `idx`: UInt32, `time`: String, `network`: String, `payload`: Data) throws -> String { +public func `peelOnionMsg`(`seed`: String, `idx`: UInt64, `time`: String, `network`: String, `payload`: Data) throws -> String { return try FfiConverterString.lift( try rustCallWithError(FfiConverterTypeSphinxError.lift) { uniffi_sphinxrs_fn_func_peel_onion_msg( FfiConverterString.lower(`seed`), - FfiConverterUInt32.lower(`idx`), + FfiConverterUInt64.lower(`idx`), FfiConverterString.lower(`time`), FfiConverterString.lower(`network`), FfiConverterData.lower(`payload`),$0) @@ -989,12 +1316,12 @@ public func `peelOnionMsg`(`seed`: String, `idx`: UInt32, `time`: String, `netwo ) } -public func `peelPayment`(`seed`: String, `idx`: UInt32, `time`: String, `network`: String, `payload`: Data, `rhash`: String, `curHeight`: UInt32, `cltvExpiry`: UInt32) throws -> Data { +public func `peelPayment`(`seed`: String, `idx`: UInt64, `time`: String, `network`: String, `payload`: Data, `rhash`: String, `curHeight`: UInt32, `cltvExpiry`: UInt32) throws -> Data { return try FfiConverterData.lift( try rustCallWithError(FfiConverterTypeSphinxError.lift) { uniffi_sphinxrs_fn_func_peel_payment( FfiConverterString.lower(`seed`), - FfiConverterUInt32.lower(`idx`), + FfiConverterUInt64.lower(`idx`), FfiConverterString.lower(`time`), FfiConverterString.lower(`network`), FfiConverterData.lower(`payload`), @@ -1005,12 +1332,12 @@ public func `peelPayment`(`seed`: String, `idx`: UInt32, `time`: String, `networ ) } -public func `peelPaymentMsg`(`seed`: String, `idx`: UInt32, `time`: String, `network`: String, `payload`: Data, `rhash`: String, `curHeight`: UInt32, `cltvExpiry`: UInt32) throws -> String { +public func `peelPaymentMsg`(`seed`: String, `idx`: UInt64, `time`: String, `network`: String, `payload`: Data, `rhash`: String, `curHeight`: UInt32, `cltvExpiry`: UInt32) throws -> String { return try FfiConverterString.lift( try rustCallWithError(FfiConverterTypeSphinxError.lift) { uniffi_sphinxrs_fn_func_peel_payment_msg( FfiConverterString.lower(`seed`), - FfiConverterUInt32.lower(`idx`), + FfiConverterUInt64.lower(`idx`), FfiConverterString.lower(`time`), FfiConverterString.lower(`network`), FfiConverterData.lower(`payload`), @@ -1021,24 +1348,24 @@ public func `peelPaymentMsg`(`seed`: String, `idx`: UInt32, `time`: String, `net ) } -public func `signMs`(`seed`: String, `idx`: UInt32, `time`: String, `network`: String) throws -> String { +public func `signMs`(`seed`: String, `idx`: UInt64, `time`: String, `network`: String) throws -> String { return try FfiConverterString.lift( try rustCallWithError(FfiConverterTypeSphinxError.lift) { uniffi_sphinxrs_fn_func_sign_ms( FfiConverterString.lower(`seed`), - FfiConverterUInt32.lower(`idx`), + FfiConverterUInt64.lower(`idx`), FfiConverterString.lower(`time`), FfiConverterString.lower(`network`),$0) } ) } -public func `signBytes`(`seed`: String, `idx`: UInt32, `time`: String, `network`: String, `msg`: Data) throws -> String { +public func `signBytes`(`seed`: String, `idx`: UInt64, `time`: String, `network`: String, `msg`: Data) throws -> String { return try FfiConverterString.lift( try rustCallWithError(FfiConverterTypeSphinxError.lift) { uniffi_sphinxrs_fn_func_sign_bytes( FfiConverterString.lower(`seed`), - FfiConverterUInt32.lower(`idx`), + FfiConverterUInt64.lower(`idx`), FfiConverterString.lower(`time`), FfiConverterString.lower(`network`), FfiConverterData.lower(`msg`),$0) @@ -1046,12 +1373,12 @@ public func `signBytes`(`seed`: String, `idx`: UInt32, `time`: String, `network` ) } -public func `pubkeyFromSeed`(`seed`: String, `idx`: UInt32, `time`: String, `network`: String) throws -> String { +public func `pubkeyFromSeed`(`seed`: String, `idx`: UInt64, `time`: String, `network`: String) throws -> String { return try FfiConverterString.lift( try rustCallWithError(FfiConverterTypeSphinxError.lift) { uniffi_sphinxrs_fn_func_pubkey_from_seed( FfiConverterString.lower(`seed`), - FfiConverterUInt32.lower(`idx`), + FfiConverterUInt64.lower(`idx`), FfiConverterString.lower(`time`), FfiConverterString.lower(`network`),$0) } @@ -1080,6 +1407,126 @@ public func `xpubFromSeed`(`seed`: String, `time`: String, `network`: String) th ) } +public func `setNetwork`(`network`: String) throws -> RunReturn { + return try FfiConverterTypeRunReturn.lift( + try rustCallWithError(FfiConverterTypeSphinxError.lift) { + uniffi_sphinxrs_fn_func_set_network( + FfiConverterString.lower(`network`),$0) +} + ) +} + +public func `setBlockheight`(`blockheight`: UInt32) throws -> RunReturn { + return try FfiConverterTypeRunReturn.lift( + try rustCallWithError(FfiConverterTypeSphinxError.lift) { + uniffi_sphinxrs_fn_func_set_blockheight( + FfiConverterUInt32.lower(`blockheight`),$0) +} + ) +} + +public func `addContact`(`seed`: String, `uniqueTime`: String, `state`: Data, `toPubkey`: String, `routeHint`: String, `myAlias`: String, `myImg`: String, `amtMsat`: UInt64) throws -> RunReturn { + return try FfiConverterTypeRunReturn.lift( + try rustCallWithError(FfiConverterTypeSphinxError.lift) { + uniffi_sphinxrs_fn_func_add_contact( + FfiConverterString.lower(`seed`), + FfiConverterString.lower(`uniqueTime`), + FfiConverterData.lower(`state`), + FfiConverterString.lower(`toPubkey`), + FfiConverterString.lower(`routeHint`), + FfiConverterString.lower(`myAlias`), + FfiConverterString.lower(`myImg`), + FfiConverterUInt64.lower(`amtMsat`),$0) +} + ) +} + +public func `getContact`(`state`: Data, `pubkey`: String) throws -> String { + return try FfiConverterString.lift( + try rustCallWithError(FfiConverterTypeSphinxError.lift) { + uniffi_sphinxrs_fn_func_get_contact( + FfiConverterData.lower(`state`), + FfiConverterString.lower(`pubkey`),$0) +} + ) +} + +public func `listContacts`(`state`: Data) throws -> String { + return try FfiConverterString.lift( + try rustCallWithError(FfiConverterTypeSphinxError.lift) { + uniffi_sphinxrs_fn_func_list_contacts( + FfiConverterData.lower(`state`),$0) +} + ) +} + +public func `getSubscriptionTopic`(`seed`: String, `uniqueTime`: String, `state`: Data) throws -> String { + return try FfiConverterString.lift( + try rustCallWithError(FfiConverterTypeSphinxError.lift) { + uniffi_sphinxrs_fn_func_get_subscription_topic( + FfiConverterString.lower(`seed`), + FfiConverterString.lower(`uniqueTime`), + FfiConverterData.lower(`state`),$0) +} + ) +} + +public func `initialSetup`(`seed`: String, `uniqueTime`: String, `state`: Data) throws -> RunReturn { + return try FfiConverterTypeRunReturn.lift( + try rustCallWithError(FfiConverterTypeSphinxError.lift) { + uniffi_sphinxrs_fn_func_initial_setup( + FfiConverterString.lower(`seed`), + FfiConverterString.lower(`uniqueTime`), + FfiConverterData.lower(`state`),$0) +} + ) +} + +public func `fetchMsgs`(`seed`: String, `uniqueTime`: String, `state`: Data, `lastMsgIdx`: UInt64, `limit`: UInt32?) throws -> RunReturn { + return try FfiConverterTypeRunReturn.lift( + try rustCallWithError(FfiConverterTypeSphinxError.lift) { + uniffi_sphinxrs_fn_func_fetch_msgs( + FfiConverterString.lower(`seed`), + FfiConverterString.lower(`uniqueTime`), + FfiConverterData.lower(`state`), + FfiConverterUInt64.lower(`lastMsgIdx`), + FfiConverterOptionUInt32.lower(`limit`),$0) +} + ) +} + +public func `handle`(`topic`: String, `payload`: Data, `seed`: String, `uniqueTime`: String, `state`: Data, `myAlias`: String, `myImg`: String) throws -> RunReturn { + return try FfiConverterTypeRunReturn.lift( + try rustCallWithError(FfiConverterTypeSphinxError.lift) { + uniffi_sphinxrs_fn_func_handle( + FfiConverterString.lower(`topic`), + FfiConverterData.lower(`payload`), + FfiConverterString.lower(`seed`), + FfiConverterString.lower(`uniqueTime`), + FfiConverterData.lower(`state`), + FfiConverterString.lower(`myAlias`), + FfiConverterString.lower(`myImg`),$0) +} + ) +} + +public func `send`(`seed`: String, `uniqueTime`: String, `to`: String, `msgType`: UInt8, `msgJson`: String, `state`: Data, `myAlias`: String, `myImg`: String, `amtMsat`: UInt64) throws -> RunReturn { + return try FfiConverterTypeRunReturn.lift( + try rustCallWithError(FfiConverterTypeSphinxError.lift) { + uniffi_sphinxrs_fn_func_send( + FfiConverterString.lower(`seed`), + FfiConverterString.lower(`uniqueTime`), + FfiConverterString.lower(`to`), + FfiConverterUInt8.lower(`msgType`), + FfiConverterString.lower(`msgJson`), + FfiConverterData.lower(`state`), + FfiConverterString.lower(`myAlias`), + FfiConverterString.lower(`myImg`), + FfiConverterUInt64.lower(`amtMsat`),$0) +} + ) +} + private enum InitializationResult { case ok case contractVersionMismatch @@ -1137,37 +1584,37 @@ private var initializationResult: InitializationResult { if (uniffi_sphinxrs_checksum_func_sha_256() != 54805) { return InitializationResult.apiChecksumMismatch } - if (uniffi_sphinxrs_checksum_func_create_onion() != 65256) { + if (uniffi_sphinxrs_checksum_func_create_onion() != 44069) { return InitializationResult.apiChecksumMismatch } - if (uniffi_sphinxrs_checksum_func_create_onion_msg() != 56460) { + if (uniffi_sphinxrs_checksum_func_create_onion_msg() != 23896) { return InitializationResult.apiChecksumMismatch } - if (uniffi_sphinxrs_checksum_func_create_keysend() != 11970) { + if (uniffi_sphinxrs_checksum_func_create_keysend() != 23547) { return InitializationResult.apiChecksumMismatch } - if (uniffi_sphinxrs_checksum_func_create_keysend_msg() != 36652) { + if (uniffi_sphinxrs_checksum_func_create_keysend_msg() != 950) { return InitializationResult.apiChecksumMismatch } - if (uniffi_sphinxrs_checksum_func_peel_onion() != 38236) { + if (uniffi_sphinxrs_checksum_func_peel_onion() != 12462) { return InitializationResult.apiChecksumMismatch } - if (uniffi_sphinxrs_checksum_func_peel_onion_msg() != 57967) { + if (uniffi_sphinxrs_checksum_func_peel_onion_msg() != 5286) { return InitializationResult.apiChecksumMismatch } - if (uniffi_sphinxrs_checksum_func_peel_payment() != 64189) { + if (uniffi_sphinxrs_checksum_func_peel_payment() != 53060) { return InitializationResult.apiChecksumMismatch } - if (uniffi_sphinxrs_checksum_func_peel_payment_msg() != 51863) { + if (uniffi_sphinxrs_checksum_func_peel_payment_msg() != 53779) { return InitializationResult.apiChecksumMismatch } - if (uniffi_sphinxrs_checksum_func_sign_ms() != 54469) { + if (uniffi_sphinxrs_checksum_func_sign_ms() != 10078) { return InitializationResult.apiChecksumMismatch } - if (uniffi_sphinxrs_checksum_func_sign_bytes() != 41645) { + if (uniffi_sphinxrs_checksum_func_sign_bytes() != 53352) { return InitializationResult.apiChecksumMismatch } - if (uniffi_sphinxrs_checksum_func_pubkey_from_seed() != 3734) { + if (uniffi_sphinxrs_checksum_func_pubkey_from_seed() != 23394) { return InitializationResult.apiChecksumMismatch } if (uniffi_sphinxrs_checksum_func_root_sign_ms() != 52594) { @@ -1176,6 +1623,36 @@ private var initializationResult: InitializationResult { if (uniffi_sphinxrs_checksum_func_xpub_from_seed() != 14922) { return InitializationResult.apiChecksumMismatch } + if (uniffi_sphinxrs_checksum_func_set_network() != 65135) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_sphinxrs_checksum_func_set_blockheight() != 43943) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_sphinxrs_checksum_func_add_contact() != 51154) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_sphinxrs_checksum_func_get_contact() != 19847) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_sphinxrs_checksum_func_list_contacts() != 18133) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_sphinxrs_checksum_func_get_subscription_topic() != 12763) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_sphinxrs_checksum_func_initial_setup() != 63727) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_sphinxrs_checksum_func_fetch_msgs() != 12460) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_sphinxrs_checksum_func_handle() != 58131) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_sphinxrs_checksum_func_send() != 22190) { + return InitializationResult.apiChecksumMismatch + } return InitializationResult.ok } diff --git a/sphinx-ffi/src/sphinxrs.udl b/sphinx-ffi/src/sphinxrs.udl index 4905352..9364b11 100644 --- a/sphinx-ffi/src/sphinxrs.udl +++ b/sphinx-ffi/src/sphinxrs.udl @@ -20,6 +20,13 @@ interface SphinxError { VlsFailed(string r); BadChildIndex(string r); BadMsg(string r); + AddContactFailed(string r); + GetContactFailed(string r); + HandleFailed(string r); + FetchMsgsFailed(string r); + SendFailed(string r); + SetNetworkFailed(string r); + SetBlockheightFailed(string r); }; dictionary Keys { @@ -35,6 +42,25 @@ dictionary VlsResponse { bytes state; }; +dictionary RunReturn { + string? topic_0; + bytes? payload_0; + string? topic_1; + bytes? payload_1; + string? topic_2; + bytes? payload_2; + bytes? state_mp; + string? msg; + string? msg_uuid; + string? msg_index; + string? msg_sender; + u64? new_balance; + string? my_contact_info; + string? sent_status; + string? settled_status; + string? error; +}; + namespace sphinxrs { [Throws=SphinxError] string pubkey_from_secret_key(string my_secret_key); @@ -64,29 +90,49 @@ namespace sphinxrs { VlsResponse run(string topic, string args, bytes state, bytes msg1, u16? expected_sequence); string sha_256(bytes msg); [Throws=SphinxError] - bytes create_onion(string seed, u32 idx, string time, string network, string hops, bytes payload); + bytes create_onion(string seed, u64 idx, string time, string network, string hops, bytes payload); [Throws=SphinxError] - bytes create_onion_msg(string seed, u32 idx, string time, string network, string hops, string json); + bytes create_onion_msg(string seed, u64 idx, string time, string network, string hops, string json); [Throws=SphinxError] - bytes create_keysend(string seed, u32 idx, string time, string network, string hops, u64 msat, string rhash, bytes payload, u32 curr_height, string preimage); + bytes create_keysend(string seed, u64 idx, string time, string network, string hops, u64 msat, string rhash, bytes payload, u32 curr_height, string preimage); [Throws=SphinxError] - bytes create_keysend_msg(string seed, u32 idx, string time, string network, string hops, u64 msat, string rhash, string msg_json, u32 curr_height, string preimage); + bytes create_keysend_msg(string seed, u64 idx, string time, string network, string hops, u64 msat, string rhash, string msg_json, u32 curr_height, string preimage); [Throws=SphinxError] - bytes peel_onion(string seed, u32 idx, string time, string network, bytes payload); + bytes peel_onion(string seed, u64 idx, string time, string network, bytes payload); [Throws=SphinxError] - string peel_onion_msg(string seed, u32 idx, string time, string network, bytes payload); + string peel_onion_msg(string seed, u64 idx, string time, string network, bytes payload); [Throws=SphinxError] - bytes peel_payment(string seed, u32 idx, string time, string network, bytes payload, string rhash, u32 cur_height, u32 cltv_expiry); + bytes peel_payment(string seed, u64 idx, string time, string network, bytes payload, string rhash, u32 cur_height, u32 cltv_expiry); [Throws=SphinxError] - string peel_payment_msg(string seed, u32 idx, string time, string network, bytes payload, string rhash, u32 cur_height, u32 cltv_expiry); + string peel_payment_msg(string seed, u64 idx, string time, string network, bytes payload, string rhash, u32 cur_height, u32 cltv_expiry); [Throws=SphinxError] - string sign_ms(string seed, u32 idx, string time, string network); + string sign_ms(string seed, u64 idx, string time, string network); [Throws=SphinxError] - string sign_bytes(string seed, u32 idx, string time, string network, bytes msg); + string sign_bytes(string seed, u64 idx, string time, string network, bytes msg); [Throws=SphinxError] - string pubkey_from_seed(string seed, u32 idx, string time, string network); + string pubkey_from_seed(string seed, u64 idx, string time, string network); [Throws=SphinxError] string root_sign_ms(string seed, string time, string network); [Throws=SphinxError] string xpub_from_seed(string seed, string time, string network); + [Throws=SphinxError] + RunReturn set_network(string network); + [Throws=SphinxError] + RunReturn set_blockheight(u32 blockheight); + [Throws=SphinxError] + RunReturn add_contact(string seed, string unique_time, bytes state, string to_pubkey, string route_hint, string my_alias, string my_img, u64 amt_msat); + [Throws=SphinxError] + string get_contact(bytes state, string pubkey); + [Throws=SphinxError] + string list_contacts(bytes state); + [Throws=SphinxError] + string get_subscription_topic(string seed, string unique_time, bytes state); + [Throws=SphinxError] + RunReturn initial_setup(string seed, string unique_time, bytes state); + [Throws=SphinxError] + RunReturn fetch_msgs(string seed, string unique_time, bytes state, u64 last_msg_idx, u32? limit); + [Throws=SphinxError] + RunReturn handle(string topic, bytes payload, string seed, string unique_time, bytes state, string my_alias, string my_img); + [Throws=SphinxError] + RunReturn send(string seed, string unique_time, string to, u8 msg_type, string msg_json, bytes state, string my_alias, string my_img, u64 amt_msat); }; \ No newline at end of file diff --git a/sphinx-ffi/src/sphinxrsFFI.h b/sphinx-ffi/src/sphinxrsFFI.h index b5ede2a..41e8f6f 100644 --- a/sphinx-ffi/src/sphinxrsFFI.h +++ b/sphinx-ffi/src/sphinxrsFFI.h @@ -91,32 +91,52 @@ RustBuffer uniffi_sphinxrs_fn_func_run(RustBuffer topic, RustBuffer args, RustBu ); RustBuffer uniffi_sphinxrs_fn_func_sha_256(RustBuffer msg, RustCallStatus *_Nonnull out_status ); -RustBuffer uniffi_sphinxrs_fn_func_create_onion(RustBuffer seed, uint32_t idx, RustBuffer time, RustBuffer network, RustBuffer hops, RustBuffer payload, RustCallStatus *_Nonnull out_status +RustBuffer uniffi_sphinxrs_fn_func_create_onion(RustBuffer seed, uint64_t idx, RustBuffer time, RustBuffer network, RustBuffer hops, RustBuffer payload, RustCallStatus *_Nonnull out_status ); -RustBuffer uniffi_sphinxrs_fn_func_create_onion_msg(RustBuffer seed, uint32_t idx, RustBuffer time, RustBuffer network, RustBuffer hops, RustBuffer json, RustCallStatus *_Nonnull out_status +RustBuffer uniffi_sphinxrs_fn_func_create_onion_msg(RustBuffer seed, uint64_t idx, RustBuffer time, RustBuffer network, RustBuffer hops, RustBuffer json, RustCallStatus *_Nonnull out_status ); -RustBuffer uniffi_sphinxrs_fn_func_create_keysend(RustBuffer seed, uint32_t idx, RustBuffer time, RustBuffer network, RustBuffer hops, uint64_t msat, RustBuffer rhash, RustBuffer payload, uint32_t curr_height, RustBuffer preimage, RustCallStatus *_Nonnull out_status +RustBuffer uniffi_sphinxrs_fn_func_create_keysend(RustBuffer seed, uint64_t idx, RustBuffer time, RustBuffer network, RustBuffer hops, uint64_t msat, RustBuffer rhash, RustBuffer payload, uint32_t curr_height, RustBuffer preimage, RustCallStatus *_Nonnull out_status ); -RustBuffer uniffi_sphinxrs_fn_func_create_keysend_msg(RustBuffer seed, uint32_t idx, RustBuffer time, RustBuffer network, RustBuffer hops, uint64_t msat, RustBuffer rhash, RustBuffer msg_json, uint32_t curr_height, RustBuffer preimage, RustCallStatus *_Nonnull out_status +RustBuffer uniffi_sphinxrs_fn_func_create_keysend_msg(RustBuffer seed, uint64_t idx, RustBuffer time, RustBuffer network, RustBuffer hops, uint64_t msat, RustBuffer rhash, RustBuffer msg_json, uint32_t curr_height, RustBuffer preimage, RustCallStatus *_Nonnull out_status ); -RustBuffer uniffi_sphinxrs_fn_func_peel_onion(RustBuffer seed, uint32_t idx, RustBuffer time, RustBuffer network, RustBuffer payload, RustCallStatus *_Nonnull out_status +RustBuffer uniffi_sphinxrs_fn_func_peel_onion(RustBuffer seed, uint64_t idx, RustBuffer time, RustBuffer network, RustBuffer payload, RustCallStatus *_Nonnull out_status ); -RustBuffer uniffi_sphinxrs_fn_func_peel_onion_msg(RustBuffer seed, uint32_t idx, RustBuffer time, RustBuffer network, RustBuffer payload, RustCallStatus *_Nonnull out_status +RustBuffer uniffi_sphinxrs_fn_func_peel_onion_msg(RustBuffer seed, uint64_t idx, RustBuffer time, RustBuffer network, RustBuffer payload, RustCallStatus *_Nonnull out_status ); -RustBuffer uniffi_sphinxrs_fn_func_peel_payment(RustBuffer seed, uint32_t idx, RustBuffer time, RustBuffer network, RustBuffer payload, RustBuffer rhash, uint32_t cur_height, uint32_t cltv_expiry, RustCallStatus *_Nonnull out_status +RustBuffer uniffi_sphinxrs_fn_func_peel_payment(RustBuffer seed, uint64_t idx, RustBuffer time, RustBuffer network, RustBuffer payload, RustBuffer rhash, uint32_t cur_height, uint32_t cltv_expiry, RustCallStatus *_Nonnull out_status ); -RustBuffer uniffi_sphinxrs_fn_func_peel_payment_msg(RustBuffer seed, uint32_t idx, RustBuffer time, RustBuffer network, RustBuffer payload, RustBuffer rhash, uint32_t cur_height, uint32_t cltv_expiry, RustCallStatus *_Nonnull out_status +RustBuffer uniffi_sphinxrs_fn_func_peel_payment_msg(RustBuffer seed, uint64_t idx, RustBuffer time, RustBuffer network, RustBuffer payload, RustBuffer rhash, uint32_t cur_height, uint32_t cltv_expiry, RustCallStatus *_Nonnull out_status ); -RustBuffer uniffi_sphinxrs_fn_func_sign_ms(RustBuffer seed, uint32_t idx, RustBuffer time, RustBuffer network, RustCallStatus *_Nonnull out_status +RustBuffer uniffi_sphinxrs_fn_func_sign_ms(RustBuffer seed, uint64_t idx, RustBuffer time, RustBuffer network, RustCallStatus *_Nonnull out_status ); -RustBuffer uniffi_sphinxrs_fn_func_sign_bytes(RustBuffer seed, uint32_t idx, RustBuffer time, RustBuffer network, RustBuffer msg, RustCallStatus *_Nonnull out_status +RustBuffer uniffi_sphinxrs_fn_func_sign_bytes(RustBuffer seed, uint64_t idx, RustBuffer time, RustBuffer network, RustBuffer msg, RustCallStatus *_Nonnull out_status ); -RustBuffer uniffi_sphinxrs_fn_func_pubkey_from_seed(RustBuffer seed, uint32_t idx, RustBuffer time, RustBuffer network, RustCallStatus *_Nonnull out_status +RustBuffer uniffi_sphinxrs_fn_func_pubkey_from_seed(RustBuffer seed, uint64_t idx, RustBuffer time, RustBuffer network, RustCallStatus *_Nonnull out_status ); RustBuffer uniffi_sphinxrs_fn_func_root_sign_ms(RustBuffer seed, RustBuffer time, RustBuffer network, RustCallStatus *_Nonnull out_status ); RustBuffer uniffi_sphinxrs_fn_func_xpub_from_seed(RustBuffer seed, RustBuffer time, RustBuffer network, RustCallStatus *_Nonnull out_status ); +RustBuffer uniffi_sphinxrs_fn_func_set_network(RustBuffer network, RustCallStatus *_Nonnull out_status +); +RustBuffer uniffi_sphinxrs_fn_func_set_blockheight(uint32_t blockheight, RustCallStatus *_Nonnull out_status +); +RustBuffer uniffi_sphinxrs_fn_func_add_contact(RustBuffer seed, RustBuffer unique_time, RustBuffer state, RustBuffer to_pubkey, RustBuffer route_hint, RustBuffer my_alias, RustBuffer my_img, uint64_t amt_msat, RustCallStatus *_Nonnull out_status +); +RustBuffer uniffi_sphinxrs_fn_func_get_contact(RustBuffer state, RustBuffer pubkey, RustCallStatus *_Nonnull out_status +); +RustBuffer uniffi_sphinxrs_fn_func_list_contacts(RustBuffer state, RustCallStatus *_Nonnull out_status +); +RustBuffer uniffi_sphinxrs_fn_func_get_subscription_topic(RustBuffer seed, RustBuffer unique_time, RustBuffer state, RustCallStatus *_Nonnull out_status +); +RustBuffer uniffi_sphinxrs_fn_func_initial_setup(RustBuffer seed, RustBuffer unique_time, RustBuffer state, RustCallStatus *_Nonnull out_status +); +RustBuffer uniffi_sphinxrs_fn_func_fetch_msgs(RustBuffer seed, RustBuffer unique_time, RustBuffer state, uint64_t last_msg_idx, RustBuffer limit, RustCallStatus *_Nonnull out_status +); +RustBuffer uniffi_sphinxrs_fn_func_handle(RustBuffer topic, RustBuffer payload, RustBuffer seed, RustBuffer unique_time, RustBuffer state, RustBuffer my_alias, RustBuffer my_img, RustCallStatus *_Nonnull out_status +); +RustBuffer uniffi_sphinxrs_fn_func_send(RustBuffer seed, RustBuffer unique_time, RustBuffer to, uint8_t msg_type, RustBuffer msg_json, RustBuffer state, RustBuffer my_alias, RustBuffer my_img, 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 @@ -205,6 +225,36 @@ uint16_t uniffi_sphinxrs_checksum_func_root_sign_ms(void ); uint16_t uniffi_sphinxrs_checksum_func_xpub_from_seed(void +); +uint16_t uniffi_sphinxrs_checksum_func_set_network(void + +); +uint16_t uniffi_sphinxrs_checksum_func_set_blockheight(void + +); +uint16_t uniffi_sphinxrs_checksum_func_add_contact(void + +); +uint16_t uniffi_sphinxrs_checksum_func_get_contact(void + +); +uint16_t uniffi_sphinxrs_checksum_func_list_contacts(void + +); +uint16_t uniffi_sphinxrs_checksum_func_get_subscription_topic(void + +); +uint16_t uniffi_sphinxrs_checksum_func_initial_setup(void + +); +uint16_t uniffi_sphinxrs_checksum_func_fetch_msgs(void + +); +uint16_t uniffi_sphinxrs_checksum_func_handle(void + +); +uint16_t uniffi_sphinxrs_checksum_func_send(void + ); uint32_t ffi_sphinxrs_uniffi_contract_version(void diff --git a/sphinx-ffi/src/uniffi/sphinxrs/sphinxrs.kt b/sphinx-ffi/src/uniffi/sphinxrs/sphinxrs.kt index cd6a993..d01c64d 100644 --- a/sphinx-ffi/src/uniffi/sphinxrs/sphinxrs.kt +++ b/sphinx-ffi/src/uniffi/sphinxrs/sphinxrs.kt @@ -392,32 +392,52 @@ internal interface _UniFFILib : Library { ): RustBuffer.ByValue fun uniffi_sphinxrs_fn_func_sha_256(`msg`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus, ): RustBuffer.ByValue - fun uniffi_sphinxrs_fn_func_create_onion(`seed`: RustBuffer.ByValue,`idx`: Int,`time`: RustBuffer.ByValue,`network`: RustBuffer.ByValue,`hops`: RustBuffer.ByValue,`payload`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus, + fun uniffi_sphinxrs_fn_func_create_onion(`seed`: RustBuffer.ByValue,`idx`: Long,`time`: RustBuffer.ByValue,`network`: RustBuffer.ByValue,`hops`: RustBuffer.ByValue,`payload`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus, ): RustBuffer.ByValue - fun uniffi_sphinxrs_fn_func_create_onion_msg(`seed`: RustBuffer.ByValue,`idx`: Int,`time`: RustBuffer.ByValue,`network`: RustBuffer.ByValue,`hops`: RustBuffer.ByValue,`json`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus, + fun uniffi_sphinxrs_fn_func_create_onion_msg(`seed`: RustBuffer.ByValue,`idx`: Long,`time`: RustBuffer.ByValue,`network`: RustBuffer.ByValue,`hops`: RustBuffer.ByValue,`json`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus, ): RustBuffer.ByValue - fun uniffi_sphinxrs_fn_func_create_keysend(`seed`: RustBuffer.ByValue,`idx`: Int,`time`: RustBuffer.ByValue,`network`: RustBuffer.ByValue,`hops`: RustBuffer.ByValue,`msat`: Long,`rhash`: RustBuffer.ByValue,`payload`: RustBuffer.ByValue,`currHeight`: Int,`preimage`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus, + fun uniffi_sphinxrs_fn_func_create_keysend(`seed`: RustBuffer.ByValue,`idx`: Long,`time`: RustBuffer.ByValue,`network`: RustBuffer.ByValue,`hops`: RustBuffer.ByValue,`msat`: Long,`rhash`: RustBuffer.ByValue,`payload`: RustBuffer.ByValue,`currHeight`: Int,`preimage`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus, ): RustBuffer.ByValue - fun uniffi_sphinxrs_fn_func_create_keysend_msg(`seed`: RustBuffer.ByValue,`idx`: Int,`time`: RustBuffer.ByValue,`network`: RustBuffer.ByValue,`hops`: RustBuffer.ByValue,`msat`: Long,`rhash`: RustBuffer.ByValue,`msgJson`: RustBuffer.ByValue,`currHeight`: Int,`preimage`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus, + fun uniffi_sphinxrs_fn_func_create_keysend_msg(`seed`: RustBuffer.ByValue,`idx`: Long,`time`: RustBuffer.ByValue,`network`: RustBuffer.ByValue,`hops`: RustBuffer.ByValue,`msat`: Long,`rhash`: RustBuffer.ByValue,`msgJson`: RustBuffer.ByValue,`currHeight`: Int,`preimage`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus, ): RustBuffer.ByValue - fun uniffi_sphinxrs_fn_func_peel_onion(`seed`: RustBuffer.ByValue,`idx`: Int,`time`: RustBuffer.ByValue,`network`: RustBuffer.ByValue,`payload`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus, + fun uniffi_sphinxrs_fn_func_peel_onion(`seed`: RustBuffer.ByValue,`idx`: Long,`time`: RustBuffer.ByValue,`network`: RustBuffer.ByValue,`payload`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus, ): RustBuffer.ByValue - fun uniffi_sphinxrs_fn_func_peel_onion_msg(`seed`: RustBuffer.ByValue,`idx`: Int,`time`: RustBuffer.ByValue,`network`: RustBuffer.ByValue,`payload`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus, + fun uniffi_sphinxrs_fn_func_peel_onion_msg(`seed`: RustBuffer.ByValue,`idx`: Long,`time`: RustBuffer.ByValue,`network`: RustBuffer.ByValue,`payload`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus, ): RustBuffer.ByValue - fun uniffi_sphinxrs_fn_func_peel_payment(`seed`: RustBuffer.ByValue,`idx`: Int,`time`: RustBuffer.ByValue,`network`: RustBuffer.ByValue,`payload`: RustBuffer.ByValue,`rhash`: RustBuffer.ByValue,`curHeight`: Int,`cltvExpiry`: Int,_uniffi_out_err: RustCallStatus, + fun uniffi_sphinxrs_fn_func_peel_payment(`seed`: RustBuffer.ByValue,`idx`: Long,`time`: RustBuffer.ByValue,`network`: RustBuffer.ByValue,`payload`: RustBuffer.ByValue,`rhash`: RustBuffer.ByValue,`curHeight`: Int,`cltvExpiry`: Int,_uniffi_out_err: RustCallStatus, ): RustBuffer.ByValue - fun uniffi_sphinxrs_fn_func_peel_payment_msg(`seed`: RustBuffer.ByValue,`idx`: Int,`time`: RustBuffer.ByValue,`network`: RustBuffer.ByValue,`payload`: RustBuffer.ByValue,`rhash`: RustBuffer.ByValue,`curHeight`: Int,`cltvExpiry`: Int,_uniffi_out_err: RustCallStatus, + fun uniffi_sphinxrs_fn_func_peel_payment_msg(`seed`: RustBuffer.ByValue,`idx`: Long,`time`: RustBuffer.ByValue,`network`: RustBuffer.ByValue,`payload`: RustBuffer.ByValue,`rhash`: RustBuffer.ByValue,`curHeight`: Int,`cltvExpiry`: Int,_uniffi_out_err: RustCallStatus, ): RustBuffer.ByValue - fun uniffi_sphinxrs_fn_func_sign_ms(`seed`: RustBuffer.ByValue,`idx`: Int,`time`: RustBuffer.ByValue,`network`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus, + fun uniffi_sphinxrs_fn_func_sign_ms(`seed`: RustBuffer.ByValue,`idx`: Long,`time`: RustBuffer.ByValue,`network`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus, ): RustBuffer.ByValue - fun uniffi_sphinxrs_fn_func_sign_bytes(`seed`: RustBuffer.ByValue,`idx`: Int,`time`: RustBuffer.ByValue,`network`: RustBuffer.ByValue,`msg`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus, + fun uniffi_sphinxrs_fn_func_sign_bytes(`seed`: RustBuffer.ByValue,`idx`: Long,`time`: RustBuffer.ByValue,`network`: RustBuffer.ByValue,`msg`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus, ): RustBuffer.ByValue - fun uniffi_sphinxrs_fn_func_pubkey_from_seed(`seed`: RustBuffer.ByValue,`idx`: Int,`time`: RustBuffer.ByValue,`network`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus, + fun uniffi_sphinxrs_fn_func_pubkey_from_seed(`seed`: RustBuffer.ByValue,`idx`: Long,`time`: RustBuffer.ByValue,`network`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus, ): RustBuffer.ByValue fun uniffi_sphinxrs_fn_func_root_sign_ms(`seed`: RustBuffer.ByValue,`time`: RustBuffer.ByValue,`network`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus, ): RustBuffer.ByValue fun uniffi_sphinxrs_fn_func_xpub_from_seed(`seed`: RustBuffer.ByValue,`time`: RustBuffer.ByValue,`network`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus, ): RustBuffer.ByValue + fun uniffi_sphinxrs_fn_func_set_network(`network`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus, + ): RustBuffer.ByValue + fun uniffi_sphinxrs_fn_func_set_blockheight(`blockheight`: Int,_uniffi_out_err: RustCallStatus, + ): RustBuffer.ByValue + fun uniffi_sphinxrs_fn_func_add_contact(`seed`: RustBuffer.ByValue,`uniqueTime`: RustBuffer.ByValue,`state`: RustBuffer.ByValue,`toPubkey`: RustBuffer.ByValue,`routeHint`: RustBuffer.ByValue,`myAlias`: RustBuffer.ByValue,`myImg`: RustBuffer.ByValue,`amtMsat`: Long,_uniffi_out_err: RustCallStatus, + ): RustBuffer.ByValue + fun uniffi_sphinxrs_fn_func_get_contact(`state`: RustBuffer.ByValue,`pubkey`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus, + ): RustBuffer.ByValue + fun uniffi_sphinxrs_fn_func_list_contacts(`state`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus, + ): RustBuffer.ByValue + fun uniffi_sphinxrs_fn_func_get_subscription_topic(`seed`: RustBuffer.ByValue,`uniqueTime`: RustBuffer.ByValue,`state`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus, + ): RustBuffer.ByValue + fun uniffi_sphinxrs_fn_func_initial_setup(`seed`: RustBuffer.ByValue,`uniqueTime`: RustBuffer.ByValue,`state`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus, + ): RustBuffer.ByValue + fun uniffi_sphinxrs_fn_func_fetch_msgs(`seed`: RustBuffer.ByValue,`uniqueTime`: RustBuffer.ByValue,`state`: RustBuffer.ByValue,`lastMsgIdx`: Long,`limit`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus, + ): RustBuffer.ByValue + fun uniffi_sphinxrs_fn_func_handle(`topic`: RustBuffer.ByValue,`payload`: RustBuffer.ByValue,`seed`: RustBuffer.ByValue,`uniqueTime`: RustBuffer.ByValue,`state`: RustBuffer.ByValue,`myAlias`: RustBuffer.ByValue,`myImg`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus, + ): RustBuffer.ByValue + fun uniffi_sphinxrs_fn_func_send(`seed`: RustBuffer.ByValue,`uniqueTime`: RustBuffer.ByValue,`to`: RustBuffer.ByValue,`msgType`: Byte,`msgJson`: RustBuffer.ByValue,`state`: RustBuffer.ByValue,`myAlias`: RustBuffer.ByValue,`myImg`: 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, @@ -480,6 +500,26 @@ internal interface _UniFFILib : Library { ): Short fun uniffi_sphinxrs_checksum_func_xpub_from_seed( ): Short + fun uniffi_sphinxrs_checksum_func_set_network( + ): Short + fun uniffi_sphinxrs_checksum_func_set_blockheight( + ): Short + fun uniffi_sphinxrs_checksum_func_add_contact( + ): Short + fun uniffi_sphinxrs_checksum_func_get_contact( + ): Short + fun uniffi_sphinxrs_checksum_func_list_contacts( + ): Short + fun uniffi_sphinxrs_checksum_func_get_subscription_topic( + ): Short + fun uniffi_sphinxrs_checksum_func_initial_setup( + ): Short + fun uniffi_sphinxrs_checksum_func_fetch_msgs( + ): Short + fun uniffi_sphinxrs_checksum_func_handle( + ): Short + fun uniffi_sphinxrs_checksum_func_send( + ): Short fun ffi_sphinxrs_uniffi_contract_version( ): Int @@ -539,37 +579,37 @@ private fun uniffiCheckApiChecksums(lib: _UniFFILib) { if (lib.uniffi_sphinxrs_checksum_func_sha_256() != 54805.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } - if (lib.uniffi_sphinxrs_checksum_func_create_onion() != 65256.toShort()) { + if (lib.uniffi_sphinxrs_checksum_func_create_onion() != 44069.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } - if (lib.uniffi_sphinxrs_checksum_func_create_onion_msg() != 56460.toShort()) { + if (lib.uniffi_sphinxrs_checksum_func_create_onion_msg() != 23896.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } - if (lib.uniffi_sphinxrs_checksum_func_create_keysend() != 11970.toShort()) { + if (lib.uniffi_sphinxrs_checksum_func_create_keysend() != 23547.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } - if (lib.uniffi_sphinxrs_checksum_func_create_keysend_msg() != 36652.toShort()) { + if (lib.uniffi_sphinxrs_checksum_func_create_keysend_msg() != 950.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } - if (lib.uniffi_sphinxrs_checksum_func_peel_onion() != 38236.toShort()) { + if (lib.uniffi_sphinxrs_checksum_func_peel_onion() != 12462.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } - if (lib.uniffi_sphinxrs_checksum_func_peel_onion_msg() != 57967.toShort()) { + if (lib.uniffi_sphinxrs_checksum_func_peel_onion_msg() != 5286.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } - if (lib.uniffi_sphinxrs_checksum_func_peel_payment() != 64189.toShort()) { + if (lib.uniffi_sphinxrs_checksum_func_peel_payment() != 53060.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } - if (lib.uniffi_sphinxrs_checksum_func_peel_payment_msg() != 51863.toShort()) { + if (lib.uniffi_sphinxrs_checksum_func_peel_payment_msg() != 53779.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } - if (lib.uniffi_sphinxrs_checksum_func_sign_ms() != 54469.toShort()) { + if (lib.uniffi_sphinxrs_checksum_func_sign_ms() != 10078.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } - if (lib.uniffi_sphinxrs_checksum_func_sign_bytes() != 41645.toShort()) { + if (lib.uniffi_sphinxrs_checksum_func_sign_bytes() != 53352.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } - if (lib.uniffi_sphinxrs_checksum_func_pubkey_from_seed() != 3734.toShort()) { + if (lib.uniffi_sphinxrs_checksum_func_pubkey_from_seed() != 23394.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } if (lib.uniffi_sphinxrs_checksum_func_root_sign_ms() != 52594.toShort()) { @@ -578,11 +618,61 @@ private fun uniffiCheckApiChecksums(lib: _UniFFILib) { if (lib.uniffi_sphinxrs_checksum_func_xpub_from_seed() != 14922.toShort()) { throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") } + if (lib.uniffi_sphinxrs_checksum_func_set_network() != 65135.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_sphinxrs_checksum_func_set_blockheight() != 43943.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_sphinxrs_checksum_func_add_contact() != 51154.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_sphinxrs_checksum_func_get_contact() != 19847.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_sphinxrs_checksum_func_list_contacts() != 18133.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_sphinxrs_checksum_func_get_subscription_topic() != 12763.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_sphinxrs_checksum_func_initial_setup() != 63727.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_sphinxrs_checksum_func_fetch_msgs() != 12460.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_sphinxrs_checksum_func_handle() != 58131.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } + if (lib.uniffi_sphinxrs_checksum_func_send() != 22190.toShort()) { + throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } } // Public interface members begin here. +public object FfiConverterUByte: FfiConverter { + override fun lift(value: Byte): UByte { + return value.toUByte() + } + + override fun read(buf: ByteBuffer): UByte { + return lift(buf.get()) + } + + override fun lower(value: UByte): Byte { + return value.toByte() + } + + override fun allocationSize(value: UByte) = 1 + + override fun write(value: UByte, buf: ByteBuffer) { + buf.put(value.toByte()) + } +} + public object FfiConverterUShort: FfiConverter { override fun lift(value: Short): UShort { return value.toUShort() @@ -737,6 +827,91 @@ public object FfiConverterTypeKeys: FfiConverterRustBuffer { +data class RunReturn ( + var `topic0`: String?, + var `payload0`: ByteArray?, + var `topic1`: String?, + var `payload1`: ByteArray?, + var `topic2`: String?, + var `payload2`: ByteArray?, + var `stateMp`: ByteArray?, + var `msg`: String?, + var `msgUuid`: String?, + var `msgIndex`: String?, + var `msgSender`: String?, + var `newBalance`: ULong?, + var `myContactInfo`: String?, + var `sentStatus`: String?, + var `settledStatus`: String?, + var `error`: String? +) { + +} + +public object FfiConverterTypeRunReturn: FfiConverterRustBuffer { + override fun read(buf: ByteBuffer): RunReturn { + return RunReturn( + FfiConverterOptionalString.read(buf), + FfiConverterOptionalByteArray.read(buf), + FfiConverterOptionalString.read(buf), + FfiConverterOptionalByteArray.read(buf), + FfiConverterOptionalString.read(buf), + FfiConverterOptionalByteArray.read(buf), + FfiConverterOptionalByteArray.read(buf), + FfiConverterOptionalString.read(buf), + FfiConverterOptionalString.read(buf), + FfiConverterOptionalString.read(buf), + FfiConverterOptionalString.read(buf), + FfiConverterOptionalULong.read(buf), + FfiConverterOptionalString.read(buf), + FfiConverterOptionalString.read(buf), + FfiConverterOptionalString.read(buf), + FfiConverterOptionalString.read(buf), + ) + } + + override fun allocationSize(value: RunReturn) = ( + FfiConverterOptionalString.allocationSize(value.`topic0`) + + FfiConverterOptionalByteArray.allocationSize(value.`payload0`) + + FfiConverterOptionalString.allocationSize(value.`topic1`) + + FfiConverterOptionalByteArray.allocationSize(value.`payload1`) + + FfiConverterOptionalString.allocationSize(value.`topic2`) + + FfiConverterOptionalByteArray.allocationSize(value.`payload2`) + + FfiConverterOptionalByteArray.allocationSize(value.`stateMp`) + + FfiConverterOptionalString.allocationSize(value.`msg`) + + FfiConverterOptionalString.allocationSize(value.`msgUuid`) + + FfiConverterOptionalString.allocationSize(value.`msgIndex`) + + FfiConverterOptionalString.allocationSize(value.`msgSender`) + + FfiConverterOptionalULong.allocationSize(value.`newBalance`) + + FfiConverterOptionalString.allocationSize(value.`myContactInfo`) + + FfiConverterOptionalString.allocationSize(value.`sentStatus`) + + FfiConverterOptionalString.allocationSize(value.`settledStatus`) + + FfiConverterOptionalString.allocationSize(value.`error`) + ) + + override fun write(value: RunReturn, buf: ByteBuffer) { + FfiConverterOptionalString.write(value.`topic0`, buf) + FfiConverterOptionalByteArray.write(value.`payload0`, buf) + FfiConverterOptionalString.write(value.`topic1`, buf) + FfiConverterOptionalByteArray.write(value.`payload1`, buf) + FfiConverterOptionalString.write(value.`topic2`, buf) + FfiConverterOptionalByteArray.write(value.`payload2`, buf) + FfiConverterOptionalByteArray.write(value.`stateMp`, buf) + FfiConverterOptionalString.write(value.`msg`, buf) + FfiConverterOptionalString.write(value.`msgUuid`, buf) + FfiConverterOptionalString.write(value.`msgIndex`, buf) + FfiConverterOptionalString.write(value.`msgSender`, buf) + FfiConverterOptionalULong.write(value.`newBalance`, buf) + FfiConverterOptionalString.write(value.`myContactInfo`, buf) + FfiConverterOptionalString.write(value.`sentStatus`, buf) + FfiConverterOptionalString.write(value.`settledStatus`, buf) + FfiConverterOptionalString.write(value.`error`, buf) + } +} + + + + data class VlsResponse ( var `topic`: String, var `bytes`: ByteArray, @@ -922,6 +1097,55 @@ sealed class SphinxException: Exception() { get() = "r=${ `r` }" } + class AddContactFailed( + val `r`: String + ) : SphinxException() { + override val message + get() = "r=${ `r` }" + } + + class GetContactFailed( + val `r`: String + ) : SphinxException() { + override val message + get() = "r=${ `r` }" + } + + class HandleFailed( + val `r`: String + ) : SphinxException() { + override val message + get() = "r=${ `r` }" + } + + class FetchMsgsFailed( + val `r`: String + ) : SphinxException() { + override val message + get() = "r=${ `r` }" + } + + class SendFailed( + val `r`: String + ) : SphinxException() { + override val message + get() = "r=${ `r` }" + } + + class SetNetworkFailed( + val `r`: String + ) : SphinxException() { + override val message + get() = "r=${ `r` }" + } + + class SetBlockheightFailed( + val `r`: String + ) : SphinxException() { + override val message + get() = "r=${ `r` }" + } + companion object ErrorHandler : CallStatusErrorHandler { override fun lift(error_buf: RustBuffer.ByValue): SphinxException = FfiConverterTypeSphinxError.lift(error_buf) @@ -995,6 +1219,27 @@ public object FfiConverterTypeSphinxError : FfiConverterRustBuffer SphinxException.BadMsg( FfiConverterString.read(buf), ) + 21 -> SphinxException.AddContactFailed( + FfiConverterString.read(buf), + ) + 22 -> SphinxException.GetContactFailed( + FfiConverterString.read(buf), + ) + 23 -> SphinxException.HandleFailed( + FfiConverterString.read(buf), + ) + 24 -> SphinxException.FetchMsgsFailed( + FfiConverterString.read(buf), + ) + 25 -> SphinxException.SendFailed( + FfiConverterString.read(buf), + ) + 26 -> SphinxException.SetNetworkFailed( + FfiConverterString.read(buf), + ) + 27 -> SphinxException.SetBlockheightFailed( + FfiConverterString.read(buf), + ) else -> throw RuntimeException("invalid error enum value, something is very wrong!!") } } @@ -1101,6 +1346,41 @@ public object FfiConverterTypeSphinxError : FfiConverterRustBuffer ( + // Add the size for the Int that specifies the variant plus the size needed for all fields + 4 + + FfiConverterString.allocationSize(value.`r`) + ) + is SphinxException.GetContactFailed -> ( + // Add the size for the Int that specifies the variant plus the size needed for all fields + 4 + + FfiConverterString.allocationSize(value.`r`) + ) + is SphinxException.HandleFailed -> ( + // Add the size for the Int that specifies the variant plus the size needed for all fields + 4 + + FfiConverterString.allocationSize(value.`r`) + ) + is SphinxException.FetchMsgsFailed -> ( + // Add the size for the Int that specifies the variant plus the size needed for all fields + 4 + + FfiConverterString.allocationSize(value.`r`) + ) + is SphinxException.SendFailed -> ( + // Add the size for the Int that specifies the variant plus the size needed for all fields + 4 + + FfiConverterString.allocationSize(value.`r`) + ) + is SphinxException.SetNetworkFailed -> ( + // Add the size for the Int that specifies the variant plus the size needed for all fields + 4 + + FfiConverterString.allocationSize(value.`r`) + ) + is SphinxException.SetBlockheightFailed -> ( + // Add the size for the Int that specifies the variant plus the size needed for all fields + 4 + + FfiConverterString.allocationSize(value.`r`) + ) } } @@ -1206,6 +1486,41 @@ public object FfiConverterTypeSphinxError : FfiConverterRustBuffer { + buf.putInt(21) + FfiConverterString.write(value.`r`, buf) + Unit + } + is SphinxException.GetContactFailed -> { + buf.putInt(22) + FfiConverterString.write(value.`r`, buf) + Unit + } + is SphinxException.HandleFailed -> { + buf.putInt(23) + FfiConverterString.write(value.`r`, buf) + Unit + } + is SphinxException.FetchMsgsFailed -> { + buf.putInt(24) + FfiConverterString.write(value.`r`, buf) + Unit + } + is SphinxException.SendFailed -> { + buf.putInt(25) + FfiConverterString.write(value.`r`, buf) + Unit + } + is SphinxException.SetNetworkFailed -> { + buf.putInt(26) + FfiConverterString.write(value.`r`, buf) + Unit + } + is SphinxException.SetBlockheightFailed -> { + buf.putInt(27) + FfiConverterString.write(value.`r`, buf) + Unit + } }.let { /* this makes the `when` an expression, which ensures it is exhaustive */ } } @@ -1239,6 +1554,122 @@ public object FfiConverterOptionalUShort: FfiConverterRustBuffer { } } } + + + + +public object FfiConverterOptionalUInt: FfiConverterRustBuffer { + override fun read(buf: ByteBuffer): UInt? { + if (buf.get().toInt() == 0) { + return null + } + return FfiConverterUInt.read(buf) + } + + override fun allocationSize(value: UInt?): Int { + if (value == null) { + return 1 + } else { + return 1 + FfiConverterUInt.allocationSize(value) + } + } + + override fun write(value: UInt?, buf: ByteBuffer) { + if (value == null) { + buf.put(0) + } else { + buf.put(1) + FfiConverterUInt.write(value, buf) + } + } +} + + + + +public object FfiConverterOptionalULong: FfiConverterRustBuffer { + override fun read(buf: ByteBuffer): ULong? { + if (buf.get().toInt() == 0) { + return null + } + return FfiConverterULong.read(buf) + } + + override fun allocationSize(value: ULong?): Int { + if (value == null) { + return 1 + } else { + return 1 + FfiConverterULong.allocationSize(value) + } + } + + override fun write(value: ULong?, buf: ByteBuffer) { + if (value == null) { + buf.put(0) + } else { + buf.put(1) + FfiConverterULong.write(value, buf) + } + } +} + + + + +public object FfiConverterOptionalString: FfiConverterRustBuffer { + override fun read(buf: ByteBuffer): String? { + if (buf.get().toInt() == 0) { + return null + } + return FfiConverterString.read(buf) + } + + override fun allocationSize(value: String?): Int { + if (value == null) { + return 1 + } else { + return 1 + FfiConverterString.allocationSize(value) + } + } + + override fun write(value: String?, buf: ByteBuffer) { + if (value == null) { + buf.put(0) + } else { + buf.put(1) + FfiConverterString.write(value, buf) + } + } +} + + + + +public object FfiConverterOptionalByteArray: FfiConverterRustBuffer { + override fun read(buf: ByteBuffer): ByteArray? { + if (buf.get().toInt() == 0) { + return null + } + return FfiConverterByteArray.read(buf) + } + + override fun allocationSize(value: ByteArray?): Int { + if (value == null) { + return 1 + } else { + return 1 + FfiConverterByteArray.allocationSize(value) + } + } + + override fun write(value: ByteArray?, buf: ByteBuffer) { + if (value == null) { + buf.put(0) + } else { + buf.put(1) + FfiConverterByteArray.write(value, buf) + } + } +} @Throws(SphinxException::class) fun `pubkeyFromSecretKey`(`mySecretKey`: String): String { @@ -1366,100 +1797,100 @@ fun `sha256`(`msg`: ByteArray): String { @Throws(SphinxException::class) -fun `createOnion`(`seed`: String, `idx`: UInt, `time`: String, `network`: String, `hops`: String, `payload`: ByteArray): ByteArray { +fun `createOnion`(`seed`: String, `idx`: ULong, `time`: String, `network`: String, `hops`: String, `payload`: ByteArray): ByteArray { return FfiConverterByteArray.lift( rustCallWithError(SphinxException) { _status -> - _UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_create_onion(FfiConverterString.lower(`seed`),FfiConverterUInt.lower(`idx`),FfiConverterString.lower(`time`),FfiConverterString.lower(`network`),FfiConverterString.lower(`hops`),FfiConverterByteArray.lower(`payload`),_status) + _UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_create_onion(FfiConverterString.lower(`seed`),FfiConverterULong.lower(`idx`),FfiConverterString.lower(`time`),FfiConverterString.lower(`network`),FfiConverterString.lower(`hops`),FfiConverterByteArray.lower(`payload`),_status) }) } @Throws(SphinxException::class) -fun `createOnionMsg`(`seed`: String, `idx`: UInt, `time`: String, `network`: String, `hops`: String, `json`: String): ByteArray { +fun `createOnionMsg`(`seed`: String, `idx`: ULong, `time`: String, `network`: String, `hops`: String, `json`: String): ByteArray { return FfiConverterByteArray.lift( rustCallWithError(SphinxException) { _status -> - _UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_create_onion_msg(FfiConverterString.lower(`seed`),FfiConverterUInt.lower(`idx`),FfiConverterString.lower(`time`),FfiConverterString.lower(`network`),FfiConverterString.lower(`hops`),FfiConverterString.lower(`json`),_status) + _UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_create_onion_msg(FfiConverterString.lower(`seed`),FfiConverterULong.lower(`idx`),FfiConverterString.lower(`time`),FfiConverterString.lower(`network`),FfiConverterString.lower(`hops`),FfiConverterString.lower(`json`),_status) }) } @Throws(SphinxException::class) -fun `createKeysend`(`seed`: String, `idx`: UInt, `time`: String, `network`: String, `hops`: String, `msat`: ULong, `rhash`: String, `payload`: ByteArray, `currHeight`: UInt, `preimage`: String): ByteArray { +fun `createKeysend`(`seed`: String, `idx`: ULong, `time`: String, `network`: String, `hops`: String, `msat`: ULong, `rhash`: String, `payload`: ByteArray, `currHeight`: UInt, `preimage`: String): ByteArray { return FfiConverterByteArray.lift( rustCallWithError(SphinxException) { _status -> - _UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_create_keysend(FfiConverterString.lower(`seed`),FfiConverterUInt.lower(`idx`),FfiConverterString.lower(`time`),FfiConverterString.lower(`network`),FfiConverterString.lower(`hops`),FfiConverterULong.lower(`msat`),FfiConverterString.lower(`rhash`),FfiConverterByteArray.lower(`payload`),FfiConverterUInt.lower(`currHeight`),FfiConverterString.lower(`preimage`),_status) + _UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_create_keysend(FfiConverterString.lower(`seed`),FfiConverterULong.lower(`idx`),FfiConverterString.lower(`time`),FfiConverterString.lower(`network`),FfiConverterString.lower(`hops`),FfiConverterULong.lower(`msat`),FfiConverterString.lower(`rhash`),FfiConverterByteArray.lower(`payload`),FfiConverterUInt.lower(`currHeight`),FfiConverterString.lower(`preimage`),_status) }) } @Throws(SphinxException::class) -fun `createKeysendMsg`(`seed`: String, `idx`: UInt, `time`: String, `network`: String, `hops`: String, `msat`: ULong, `rhash`: String, `msgJson`: String, `currHeight`: UInt, `preimage`: String): ByteArray { +fun `createKeysendMsg`(`seed`: String, `idx`: ULong, `time`: String, `network`: String, `hops`: String, `msat`: ULong, `rhash`: String, `msgJson`: String, `currHeight`: UInt, `preimage`: String): ByteArray { return FfiConverterByteArray.lift( rustCallWithError(SphinxException) { _status -> - _UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_create_keysend_msg(FfiConverterString.lower(`seed`),FfiConverterUInt.lower(`idx`),FfiConverterString.lower(`time`),FfiConverterString.lower(`network`),FfiConverterString.lower(`hops`),FfiConverterULong.lower(`msat`),FfiConverterString.lower(`rhash`),FfiConverterString.lower(`msgJson`),FfiConverterUInt.lower(`currHeight`),FfiConverterString.lower(`preimage`),_status) + _UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_create_keysend_msg(FfiConverterString.lower(`seed`),FfiConverterULong.lower(`idx`),FfiConverterString.lower(`time`),FfiConverterString.lower(`network`),FfiConverterString.lower(`hops`),FfiConverterULong.lower(`msat`),FfiConverterString.lower(`rhash`),FfiConverterString.lower(`msgJson`),FfiConverterUInt.lower(`currHeight`),FfiConverterString.lower(`preimage`),_status) }) } @Throws(SphinxException::class) -fun `peelOnion`(`seed`: String, `idx`: UInt, `time`: String, `network`: String, `payload`: ByteArray): ByteArray { +fun `peelOnion`(`seed`: String, `idx`: ULong, `time`: String, `network`: String, `payload`: ByteArray): ByteArray { return FfiConverterByteArray.lift( rustCallWithError(SphinxException) { _status -> - _UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_peel_onion(FfiConverterString.lower(`seed`),FfiConverterUInt.lower(`idx`),FfiConverterString.lower(`time`),FfiConverterString.lower(`network`),FfiConverterByteArray.lower(`payload`),_status) + _UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_peel_onion(FfiConverterString.lower(`seed`),FfiConverterULong.lower(`idx`),FfiConverterString.lower(`time`),FfiConverterString.lower(`network`),FfiConverterByteArray.lower(`payload`),_status) }) } @Throws(SphinxException::class) -fun `peelOnionMsg`(`seed`: String, `idx`: UInt, `time`: String, `network`: String, `payload`: ByteArray): String { +fun `peelOnionMsg`(`seed`: String, `idx`: ULong, `time`: String, `network`: String, `payload`: ByteArray): String { return FfiConverterString.lift( rustCallWithError(SphinxException) { _status -> - _UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_peel_onion_msg(FfiConverterString.lower(`seed`),FfiConverterUInt.lower(`idx`),FfiConverterString.lower(`time`),FfiConverterString.lower(`network`),FfiConverterByteArray.lower(`payload`),_status) + _UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_peel_onion_msg(FfiConverterString.lower(`seed`),FfiConverterULong.lower(`idx`),FfiConverterString.lower(`time`),FfiConverterString.lower(`network`),FfiConverterByteArray.lower(`payload`),_status) }) } @Throws(SphinxException::class) -fun `peelPayment`(`seed`: String, `idx`: UInt, `time`: String, `network`: String, `payload`: ByteArray, `rhash`: String, `curHeight`: UInt, `cltvExpiry`: UInt): ByteArray { +fun `peelPayment`(`seed`: String, `idx`: ULong, `time`: String, `network`: String, `payload`: ByteArray, `rhash`: String, `curHeight`: UInt, `cltvExpiry`: UInt): ByteArray { return FfiConverterByteArray.lift( rustCallWithError(SphinxException) { _status -> - _UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_peel_payment(FfiConverterString.lower(`seed`),FfiConverterUInt.lower(`idx`),FfiConverterString.lower(`time`),FfiConverterString.lower(`network`),FfiConverterByteArray.lower(`payload`),FfiConverterString.lower(`rhash`),FfiConverterUInt.lower(`curHeight`),FfiConverterUInt.lower(`cltvExpiry`),_status) + _UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_peel_payment(FfiConverterString.lower(`seed`),FfiConverterULong.lower(`idx`),FfiConverterString.lower(`time`),FfiConverterString.lower(`network`),FfiConverterByteArray.lower(`payload`),FfiConverterString.lower(`rhash`),FfiConverterUInt.lower(`curHeight`),FfiConverterUInt.lower(`cltvExpiry`),_status) }) } @Throws(SphinxException::class) -fun `peelPaymentMsg`(`seed`: String, `idx`: UInt, `time`: String, `network`: String, `payload`: ByteArray, `rhash`: String, `curHeight`: UInt, `cltvExpiry`: UInt): String { +fun `peelPaymentMsg`(`seed`: String, `idx`: ULong, `time`: String, `network`: String, `payload`: ByteArray, `rhash`: String, `curHeight`: UInt, `cltvExpiry`: UInt): String { return FfiConverterString.lift( rustCallWithError(SphinxException) { _status -> - _UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_peel_payment_msg(FfiConverterString.lower(`seed`),FfiConverterUInt.lower(`idx`),FfiConverterString.lower(`time`),FfiConverterString.lower(`network`),FfiConverterByteArray.lower(`payload`),FfiConverterString.lower(`rhash`),FfiConverterUInt.lower(`curHeight`),FfiConverterUInt.lower(`cltvExpiry`),_status) + _UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_peel_payment_msg(FfiConverterString.lower(`seed`),FfiConverterULong.lower(`idx`),FfiConverterString.lower(`time`),FfiConverterString.lower(`network`),FfiConverterByteArray.lower(`payload`),FfiConverterString.lower(`rhash`),FfiConverterUInt.lower(`curHeight`),FfiConverterUInt.lower(`cltvExpiry`),_status) }) } @Throws(SphinxException::class) -fun `signMs`(`seed`: String, `idx`: UInt, `time`: String, `network`: String): String { +fun `signMs`(`seed`: String, `idx`: ULong, `time`: String, `network`: String): String { return FfiConverterString.lift( rustCallWithError(SphinxException) { _status -> - _UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_sign_ms(FfiConverterString.lower(`seed`),FfiConverterUInt.lower(`idx`),FfiConverterString.lower(`time`),FfiConverterString.lower(`network`),_status) + _UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_sign_ms(FfiConverterString.lower(`seed`),FfiConverterULong.lower(`idx`),FfiConverterString.lower(`time`),FfiConverterString.lower(`network`),_status) }) } @Throws(SphinxException::class) -fun `signBytes`(`seed`: String, `idx`: UInt, `time`: String, `network`: String, `msg`: ByteArray): String { +fun `signBytes`(`seed`: String, `idx`: ULong, `time`: String, `network`: String, `msg`: ByteArray): String { return FfiConverterString.lift( rustCallWithError(SphinxException) { _status -> - _UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_sign_bytes(FfiConverterString.lower(`seed`),FfiConverterUInt.lower(`idx`),FfiConverterString.lower(`time`),FfiConverterString.lower(`network`),FfiConverterByteArray.lower(`msg`),_status) + _UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_sign_bytes(FfiConverterString.lower(`seed`),FfiConverterULong.lower(`idx`),FfiConverterString.lower(`time`),FfiConverterString.lower(`network`),FfiConverterByteArray.lower(`msg`),_status) }) } @Throws(SphinxException::class) -fun `pubkeyFromSeed`(`seed`: String, `idx`: UInt, `time`: String, `network`: String): String { +fun `pubkeyFromSeed`(`seed`: String, `idx`: ULong, `time`: String, `network`: String): String { return FfiConverterString.lift( rustCallWithError(SphinxException) { _status -> - _UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_pubkey_from_seed(FfiConverterString.lower(`seed`),FfiConverterUInt.lower(`idx`),FfiConverterString.lower(`time`),FfiConverterString.lower(`network`),_status) + _UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_pubkey_from_seed(FfiConverterString.lower(`seed`),FfiConverterULong.lower(`idx`),FfiConverterString.lower(`time`),FfiConverterString.lower(`network`),_status) }) } @@ -1481,4 +1912,94 @@ fun `xpubFromSeed`(`seed`: String, `time`: String, `network`: String): String { }) } +@Throws(SphinxException::class) + +fun `setNetwork`(`network`: String): RunReturn { + return FfiConverterTypeRunReturn.lift( + rustCallWithError(SphinxException) { _status -> + _UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_set_network(FfiConverterString.lower(`network`),_status) +}) +} + +@Throws(SphinxException::class) + +fun `setBlockheight`(`blockheight`: UInt): RunReturn { + return FfiConverterTypeRunReturn.lift( + rustCallWithError(SphinxException) { _status -> + _UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_set_blockheight(FfiConverterUInt.lower(`blockheight`),_status) +}) +} + +@Throws(SphinxException::class) + +fun `addContact`(`seed`: String, `uniqueTime`: String, `state`: ByteArray, `toPubkey`: String, `routeHint`: String, `myAlias`: String, `myImg`: String, `amtMsat`: ULong): RunReturn { + return FfiConverterTypeRunReturn.lift( + rustCallWithError(SphinxException) { _status -> + _UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_add_contact(FfiConverterString.lower(`seed`),FfiConverterString.lower(`uniqueTime`),FfiConverterByteArray.lower(`state`),FfiConverterString.lower(`toPubkey`),FfiConverterString.lower(`routeHint`),FfiConverterString.lower(`myAlias`),FfiConverterString.lower(`myImg`),FfiConverterULong.lower(`amtMsat`),_status) +}) +} + +@Throws(SphinxException::class) + +fun `getContact`(`state`: ByteArray, `pubkey`: String): String { + return FfiConverterString.lift( + rustCallWithError(SphinxException) { _status -> + _UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_get_contact(FfiConverterByteArray.lower(`state`),FfiConverterString.lower(`pubkey`),_status) +}) +} + +@Throws(SphinxException::class) + +fun `listContacts`(`state`: ByteArray): String { + return FfiConverterString.lift( + rustCallWithError(SphinxException) { _status -> + _UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_list_contacts(FfiConverterByteArray.lower(`state`),_status) +}) +} + +@Throws(SphinxException::class) + +fun `getSubscriptionTopic`(`seed`: String, `uniqueTime`: String, `state`: ByteArray): String { + return FfiConverterString.lift( + rustCallWithError(SphinxException) { _status -> + _UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_get_subscription_topic(FfiConverterString.lower(`seed`),FfiConverterString.lower(`uniqueTime`),FfiConverterByteArray.lower(`state`),_status) +}) +} + +@Throws(SphinxException::class) + +fun `initialSetup`(`seed`: String, `uniqueTime`: String, `state`: ByteArray): RunReturn { + return FfiConverterTypeRunReturn.lift( + rustCallWithError(SphinxException) { _status -> + _UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_initial_setup(FfiConverterString.lower(`seed`),FfiConverterString.lower(`uniqueTime`),FfiConverterByteArray.lower(`state`),_status) +}) +} + +@Throws(SphinxException::class) + +fun `fetchMsgs`(`seed`: String, `uniqueTime`: String, `state`: ByteArray, `lastMsgIdx`: ULong, `limit`: UInt?): RunReturn { + return FfiConverterTypeRunReturn.lift( + rustCallWithError(SphinxException) { _status -> + _UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_fetch_msgs(FfiConverterString.lower(`seed`),FfiConverterString.lower(`uniqueTime`),FfiConverterByteArray.lower(`state`),FfiConverterULong.lower(`lastMsgIdx`),FfiConverterOptionalUInt.lower(`limit`),_status) +}) +} + +@Throws(SphinxException::class) + +fun `handle`(`topic`: String, `payload`: ByteArray, `seed`: String, `uniqueTime`: String, `state`: ByteArray, `myAlias`: String, `myImg`: String): RunReturn { + return FfiConverterTypeRunReturn.lift( + rustCallWithError(SphinxException) { _status -> + _UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_handle(FfiConverterString.lower(`topic`),FfiConverterByteArray.lower(`payload`),FfiConverterString.lower(`seed`),FfiConverterString.lower(`uniqueTime`),FfiConverterByteArray.lower(`state`),FfiConverterString.lower(`myAlias`),FfiConverterString.lower(`myImg`),_status) +}) +} + +@Throws(SphinxException::class) + +fun `send`(`seed`: String, `uniqueTime`: String, `to`: String, `msgType`: UByte, `msgJson`: String, `state`: ByteArray, `myAlias`: String, `myImg`: String, `amtMsat`: ULong): RunReturn { + return FfiConverterTypeRunReturn.lift( + rustCallWithError(SphinxException) { _status -> + _UniFFILib.INSTANCE.uniffi_sphinxrs_fn_func_send(FfiConverterString.lower(`seed`),FfiConverterString.lower(`uniqueTime`),FfiConverterString.lower(`to`),FfiConverterUByte.lower(`msgType`),FfiConverterString.lower(`msgJson`),FfiConverterByteArray.lower(`state`),FfiConverterString.lower(`myAlias`),FfiConverterString.lower(`myImg`),FfiConverterULong.lower(`amtMsat`),_status) +}) +} +