-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add mnemonic conversion for c-bindings
- Loading branch information
1 parent
f6712f0
commit 46f5ca7
Showing
4 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use crate::Error; | ||
use ergo_lib::ergotree_interpreter::sigma_protocol::private_input::DlogProverInput; | ||
use ergo_lib::wallet::mnemonic::Mnemonic as InnerMnemonic; | ||
|
||
/// Convert a mnemonic phrase into a mnemonic seed | ||
/// mnemonic_pass is optional and is used to salt the seed | ||
pub unsafe fn mnemonic_to_seed( | ||
mnemonic_phrase: &str, | ||
mnemonic_pass: &str, | ||
output: *mut u8, | ||
) -> Result<(), Error> { | ||
let src: Vec<u8> = InnerMnemonic::to_seed(mnemonic_phrase, mnemonic_pass).into(); | ||
std::ptr::copy_nonoverlapping(src.as_ptr(), output, DlogProverInput::SIZE_BYTES); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use ergo_lib_c_core::mnemonic::mnemonic_to_seed; | ||
use std::ffi::CStr; | ||
use std::os::raw::c_char; | ||
|
||
/// Convert a mnemonic phrase into a mnemonic seed | ||
/// mnemonic_pass is optional and is used to salt the seed | ||
#[no_mangle] | ||
pub unsafe extern "C" fn ergo_lib_mnemonic_to_seed( | ||
mnemonic_phrase: *const c_char, | ||
mnemonic_pass: *const c_char, | ||
output: *mut u8, | ||
) { | ||
let mnemonic_phrase = CStr::from_ptr(mnemonic_phrase).to_string_lossy(); | ||
let mnemonic_pass = CStr::from_ptr(mnemonic_pass).to_string_lossy(); | ||
#[allow(clippy::unwrap_used)] | ||
mnemonic_to_seed(&mnemonic_phrase, &mnemonic_pass, output).unwrap() | ||
} |