Skip to content

Commit e2e044d

Browse files
ZocoLiniclaude
andcommitted
remove key-wallet-ffi crate usage, platform-wallet-ffi wraps all the logic
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 36c5908 commit e2e044d

33 files changed

Lines changed: 268 additions & 3806 deletions

Cargo.lock

Lines changed: 0 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ dashcore = { git = "https://github.com/dashpay/rust-dashcore", rev = "53130869e5
5353
dash-network-seeds = { git = "https://github.com/dashpay/rust-dashcore", rev = "53130869e5b9343ae59016323e5e5269e717a8fd" }
5454
dash-spv = { git = "https://github.com/dashpay/rust-dashcore", rev = "53130869e5b9343ae59016323e5e5269e717a8fd" }
5555
key-wallet = { git = "https://github.com/dashpay/rust-dashcore", rev = "53130869e5b9343ae59016323e5e5269e717a8fd" }
56-
key-wallet-ffi = { git = "https://github.com/dashpay/rust-dashcore", rev = "53130869e5b9343ae59016323e5e5269e717a8fd" }
5756
key-wallet-manager = { git = "https://github.com/dashpay/rust-dashcore", rev = "53130869e5b9343ae59016323e5e5269e717a8fd" }
5857
dash-network = { git = "https://github.com/dashpay/rust-dashcore", rev = "53130869e5b9343ae59016323e5e5269e717a8fd" }
5958
dashcore-rpc = { git = "https://github.com/dashpay/rust-dashcore", rev = "53130869e5b9343ae59016323e5e5269e717a8fd" }
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//! Dash Core (on-chain) address validation.
2+
3+
use dash_network::ffi::FFINetwork;
4+
use std::ffi::CStr;
5+
use std::os::raw::c_char;
6+
use std::str::FromStr;
7+
8+
/// Validate that `address` is a well-formed Dash address on `network`.
9+
/// Any null, non-UTF-8, malformed, or wrong-network input returns `false`.
10+
///
11+
/// # Safety
12+
/// `address` must be a valid NUL-terminated C string.
13+
#[no_mangle]
14+
pub unsafe extern "C" fn platform_wallet_address_validate(
15+
address: *const c_char,
16+
network: FFINetwork,
17+
) -> bool {
18+
if address.is_null() {
19+
return false;
20+
}
21+
let Ok(address_str) = CStr::from_ptr(address).to_str() else {
22+
return false;
23+
};
24+
let Ok(parsed) = dashcore::Address::from_str(address_str) else {
25+
return false;
26+
};
27+
let net: dashcore::Network = network.into();
28+
parsed.require_network(net).is_ok()
29+
}
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
//! BIP-39 mnemonic and BIP-32 derivation primitives.
2+
//!
3+
//! Thin C-ABI wrappers over the `key-wallet` crate — the surface that
4+
//! `key-wallet-ffi` used to provide before it was dropped from this repo.
5+
6+
use crate::error::*;
7+
use crate::{check_ptr, unwrap_result_or_return};
8+
use dash_network::ffi::FFINetwork;
9+
use key_wallet::mnemonic::{Language, Mnemonic};
10+
use std::ffi::CStr;
11+
use std::os::raw::c_char;
12+
13+
/// BIP-39 wordlist language. Mirrors `key_wallet::mnemonic::Language`.
14+
#[repr(C)]
15+
#[derive(Debug, Clone, Copy)]
16+
pub enum FFILanguage {
17+
English = 0,
18+
ChineseSimplified = 1,
19+
ChineseTraditional = 2,
20+
Czech = 3,
21+
French = 4,
22+
Italian = 5,
23+
Japanese = 6,
24+
Korean = 7,
25+
Portuguese = 8,
26+
Spanish = 9,
27+
}
28+
29+
impl From<FFILanguage> for Language {
30+
fn from(language: FFILanguage) -> Self {
31+
match language {
32+
FFILanguage::English => Language::English,
33+
FFILanguage::ChineseSimplified => Language::ChineseSimplified,
34+
FFILanguage::ChineseTraditional => Language::ChineseTraditional,
35+
FFILanguage::Czech => Language::Czech,
36+
FFILanguage::French => Language::French,
37+
FFILanguage::Italian => Language::Italian,
38+
FFILanguage::Japanese => Language::Japanese,
39+
FFILanguage::Korean => Language::Korean,
40+
FFILanguage::Portuguese => Language::Portuguese,
41+
FFILanguage::Spanish => Language::Spanish,
42+
}
43+
}
44+
}
45+
46+
/// Generate a fresh BIP-39 mnemonic of `word_count` words (12, 15, 18,
47+
/// 21, or 24) in `language`. Writes a heap C string into `out_mnemonic`
48+
/// (caller frees via `platform_wallet_string_free`).
49+
///
50+
/// # Safety
51+
/// `out_mnemonic` must be a valid writable `*mut c_char` location.
52+
#[no_mangle]
53+
pub unsafe extern "C" fn platform_wallet_generate_mnemonic(
54+
word_count: u32,
55+
language: FFILanguage,
56+
out_mnemonic: *mut *mut c_char,
57+
) -> PlatformWalletFFIResult {
58+
check_ptr!(out_mnemonic);
59+
let phrase = unwrap_result_or_return!(Mnemonic::generate(word_count as usize, language.into()));
60+
let c_str = unwrap_result_or_return!(std::ffi::CString::new(phrase.to_string()));
61+
*out_mnemonic = c_str.into_raw();
62+
PlatformWalletFFIResult::ok()
63+
}
64+
65+
/// Convert a BIP-39 mnemonic to its 64-byte seed. Returns 0 on success
66+
/// (seed written to `seed_out`, length to `seed_len`), -1 on failure.
67+
///
68+
/// # Safety
69+
/// - `mnemonic` must be a valid NUL-terminated C string.
70+
/// - `passphrase` may be null or a NUL-terminated C string.
71+
/// - `seed_out` must point at >= 64 writable bytes; `seed_len` at a writable `usize`.
72+
#[no_mangle]
73+
pub unsafe extern "C" fn platform_wallet_mnemonic_to_seed(
74+
mnemonic: *const c_char,
75+
passphrase: *const c_char,
76+
seed_out: *mut u8,
77+
seed_len: *mut usize,
78+
) -> i32 {
79+
if mnemonic.is_null() || seed_out.is_null() || seed_len.is_null() {
80+
return -1;
81+
}
82+
let Ok(mnemonic_str) = CStr::from_ptr(mnemonic).to_str() else {
83+
return -1;
84+
};
85+
let passphrase_str = if passphrase.is_null() {
86+
""
87+
} else {
88+
let Ok(s) = CStr::from_ptr(passphrase).to_str() else {
89+
return -1;
90+
};
91+
s
92+
};
93+
let Ok(parsed) = Mnemonic::from_phrase(mnemonic_str, Language::English) else {
94+
return -1;
95+
};
96+
let seed = parsed.to_seed(passphrase_str);
97+
let seed_bytes: &[u8] = seed.as_ref();
98+
if seed_bytes.len() > 64 {
99+
return -1;
100+
}
101+
*seed_len = seed_bytes.len();
102+
std::ptr::copy_nonoverlapping(seed_bytes.as_ptr(), seed_out, seed_bytes.len());
103+
0
104+
}
105+
106+
/// Build the DIP-9 identity-authentication path
107+
/// `m/9'/<coin>'/5'/0'/identity_index'/key_index'`. Writes a heap C
108+
/// string into `out_path` (caller frees via `platform_wallet_string_free`).
109+
/// Returns 0 on success, -1 on failure.
110+
///
111+
/// # Safety
112+
/// `out_path` must be a valid writable `*mut c_char` location.
113+
#[no_mangle]
114+
pub unsafe extern "C" fn platform_wallet_derive_identity_authentication_path(
115+
network: FFINetwork,
116+
identity_index: u32,
117+
key_index: u32,
118+
out_path: *mut *mut c_char,
119+
) -> i32 {
120+
if out_path.is_null() {
121+
return -1;
122+
}
123+
use key_wallet::bip32::{DerivationPath, KeyDerivationType};
124+
let net: key_wallet::Network = network.into();
125+
let derivation = DerivationPath::identity_authentication_path(
126+
net,
127+
KeyDerivationType::ECDSA,
128+
identity_index,
129+
key_index,
130+
);
131+
let path_str = format!("{}", derivation);
132+
let Ok(c_str) = std::ffi::CString::new(path_str) else {
133+
return -1;
134+
};
135+
*out_path = c_str.into_raw();
136+
0
137+
}

packages/rs-platform-wallet-ffi/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub mod contact;
1414
pub mod contact_persistence;
1515
pub mod contact_request;
1616
pub mod core_address_types;
17+
pub mod core_addresses;
1718
pub mod core_wallet;
1819
pub mod core_wallet_types;
1920
pub mod dashpay;
@@ -41,6 +42,7 @@ pub mod identity_top_up;
4142
pub mod identity_transfer;
4243
pub mod identity_update;
4344
pub mod identity_withdrawal;
45+
pub mod key_wallet_ffi;
4446
pub mod managed_identity;
4547
pub mod manager;
4648
pub mod manager_diagnostics;
@@ -71,6 +73,7 @@ pub use contact::*;
7173
pub use contact_persistence::*;
7274
pub use contact_request::*;
7375
pub use core_address_types::*;
76+
pub use core_addresses::*;
7477
pub use core_wallet::*;
7578
pub use core_wallet_types::*;
7679
pub use dashpay::*;
@@ -97,6 +100,7 @@ pub use identity_top_up::*;
97100
pub use identity_transfer::*;
98101
pub use identity_update::*;
99102
pub use identity_withdrawal::*;
103+
pub use key_wallet_ffi::*;
100104
pub use managed_identity::*;
101105
pub use manager::*;
102106
pub use manager_diagnostics::*;

packages/rs-platform-wallet-ffi/src/persistence.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2313,4 +2313,3 @@ unsafe fn slice_from_raw<'a>(ptr: *const u8, len: usize) -> &'a [u8] {
23132313
slice::from_raw_parts(ptr, len)
23142314
}
23152315
}
2316-

packages/rs-sdk-ffi/cbindgen.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ documentation_style = "c99"
1616

1717
[export]
1818
include = ["dash_sdk_*", "dash_core_*", "dash_unified_sdk_*"]
19-
# Exclude types that come from key-wallet-ffi to avoid duplication
20-
exclude = ["FFIAccountType", "FFIAccountTypePreference", "FFIAccountTypeUsed", "FFIAccountCreationOptionType"]
19+
exclude = []
2120
prefix = ""
2221
item_types = ["enums", "structs", "unions", "typedefs", "opaque", "functions"]
2322

packages/rs-unified-sdk-ffi/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ rust-version.workspace = true
88
crate-type = ["staticlib", "cdylib"]
99

1010
[dependencies]
11-
key-wallet-ffi = { workspace = true }
1211
platform-wallet-ffi = { path = "../rs-platform-wallet-ffi" }
1312
rs-sdk-ffi = { path = "../rs-sdk-ffi" }
1413
dash-network = { workspace = true, features = ["ffi"] }
@@ -18,4 +17,4 @@ default = []
1817
# Forwards to `platform-wallet-ffi/shielded`. Pulls Orchard / ZK
1918
# shielded sync support into the unified iOS framework. Off by
2019
# default so the framework's transparent surface stays slim.
21-
shielded = ["platform-wallet-ffi/shielded"]
20+
shielded = ["platform-wallet-ffi/shielded"]
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
pub use dash_network;
2-
pub use key_wallet_ffi;
32
pub use platform_wallet_ffi;
43
pub use rs_sdk_ffi;

packages/swift-sdk/Sources/SwiftDashSDK/KeyWallet/Account.swift

Lines changed: 0 additions & 65 deletions
This file was deleted.

0 commit comments

Comments
 (0)