Skip to content

Commit

Permalink
fix FFI
Browse files Browse the repository at this point in the history
  • Loading branch information
Evanfeenstra committed Sep 12, 2023
1 parent 8a00ad5 commit c3c399d
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 8 deletions.
6 changes: 3 additions & 3 deletions sphinx-ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ version = "0.1.3"
authors = ["Evan Feenstra <[email protected]>"]
edition = "2018"

# [lib]
# name = "sphinxrs"
# crate-type = ["staticlib", "cdylib"]
[lib]
name = "sphinxrs"
crate-type = ["staticlib", "cdylib"]

[features]
default = ["ffi", "std"]
Expand Down
3 changes: 3 additions & 0 deletions sphinx-ffi/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
uniffi::generate_scaffolding("src/sphinxrs.udl").unwrap();
}
30 changes: 27 additions & 3 deletions sphinx-ffi/src/sphinxrs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -793,11 +793,11 @@ public func `nodeKeys`(`net`: String, `seed`: String) throws -> Keys {
)
}

public func `mnemonicFromEntropy`(`seed`: String) throws -> String {
public func `mnemonicFromEntropy`(`entropy`: String) throws -> String {
return try FfiConverterString.lift(
try rustCallWithError(FfiConverterTypeSphinxError.lift) {
uniffi_sphinxrs_fn_func_mnemonic_from_entropy(
FfiConverterString.lower(`seed`),$0)
FfiConverterString.lower(`entropy`),$0)
}
)
}
Expand All @@ -811,6 +811,24 @@ public func `entropyFromMnemonic`(`mnemonic`: String) throws -> String {
)
}

public func `mnemonicToSeed`(`mnemonic`: String) throws -> String {
return try FfiConverterString.lift(
try rustCallWithError(FfiConverterTypeSphinxError.lift) {
uniffi_sphinxrs_fn_func_mnemonic_to_seed(
FfiConverterString.lower(`mnemonic`),$0)
}
)
}

public func `entropyToSeed`(`entropy`: String) throws -> String {
return try FfiConverterString.lift(
try rustCallWithError(FfiConverterTypeSphinxError.lift) {
uniffi_sphinxrs_fn_func_entropy_to_seed(
FfiConverterString.lower(`entropy`),$0)
}
)
}

public func `buildRequest`(`msg`: String, `secret`: String, `nonce`: UInt64) throws -> String {
return try FfiConverterString.lift(
try rustCallWithError(FfiConverterTypeSphinxError.lift) {
Expand Down Expand Up @@ -884,12 +902,18 @@ private var initializationResult: InitializationResult {
if (uniffi_sphinxrs_checksum_func_node_keys() != 21192) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_sphinxrs_checksum_func_mnemonic_from_entropy() != 16221) {
if (uniffi_sphinxrs_checksum_func_mnemonic_from_entropy() != 32309) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_sphinxrs_checksum_func_entropy_from_mnemonic() != 33294) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_sphinxrs_checksum_func_mnemonic_to_seed() != 23084) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_sphinxrs_checksum_func_entropy_to_seed() != 33710) {
return InitializationResult.apiChecksumMismatch
}
if (uniffi_sphinxrs_checksum_func_build_request() != 31264) {
return InitializationResult.apiChecksumMismatch
}
Expand Down
6 changes: 5 additions & 1 deletion sphinx-ffi/src/sphinxrs.udl
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,14 @@ namespace sphinxrs {
[Throws=SphinxError]
Keys node_keys(string net, string seed);
[Throws=SphinxError]
string mnemonic_from_entropy(string seed);
string mnemonic_from_entropy(string entropy);
[Throws=SphinxError]
string entropy_from_mnemonic(string mnemonic);
[Throws=SphinxError]
string mnemonic_to_seed(string mnemonic);
[Throws=SphinxError]
string entropy_to_seed(string entropy);
[Throws=SphinxError]
string build_request(string msg, string secret, u64 nonce);
[Throws=SphinxError]
string parse_response(string res);
Expand Down
12 changes: 11 additions & 1 deletion sphinx-ffi/src/sphinxrsFFI.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,14 @@ RustBuffer uniffi_sphinxrs_fn_func_decrypt(RustBuffer ciphertext, RustBuffer sec
);
RustBuffer uniffi_sphinxrs_fn_func_node_keys(RustBuffer net, RustBuffer seed, RustCallStatus *_Nonnull out_status
);
RustBuffer uniffi_sphinxrs_fn_func_mnemonic_from_entropy(RustBuffer seed, RustCallStatus *_Nonnull out_status
RustBuffer uniffi_sphinxrs_fn_func_mnemonic_from_entropy(RustBuffer entropy, RustCallStatus *_Nonnull out_status
);
RustBuffer uniffi_sphinxrs_fn_func_entropy_from_mnemonic(RustBuffer mnemonic, RustCallStatus *_Nonnull out_status
);
RustBuffer uniffi_sphinxrs_fn_func_mnemonic_to_seed(RustBuffer mnemonic, RustCallStatus *_Nonnull out_status
);
RustBuffer uniffi_sphinxrs_fn_func_entropy_to_seed(RustBuffer entropy, RustCallStatus *_Nonnull out_status
);
RustBuffer uniffi_sphinxrs_fn_func_build_request(RustBuffer msg, RustBuffer secret, uint64_t nonce, RustCallStatus *_Nonnull out_status
);
RustBuffer uniffi_sphinxrs_fn_func_parse_response(RustBuffer res, RustCallStatus *_Nonnull out_status
Expand Down Expand Up @@ -113,6 +117,12 @@ uint16_t uniffi_sphinxrs_checksum_func_mnemonic_from_entropy(void
);
uint16_t uniffi_sphinxrs_checksum_func_entropy_from_mnemonic(void

);
uint16_t uniffi_sphinxrs_checksum_func_mnemonic_to_seed(void

);
uint16_t uniffi_sphinxrs_checksum_func_entropy_to_seed(void

);
uint16_t uniffi_sphinxrs_checksum_func_build_request(void

Expand Down

0 comments on commit c3c399d

Please sign in to comment.