Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ jobs:
- name: Run unit tests
run: cargo test
- name: Build and run sample/rust
run: cd samples/rust && cargo run && cd ../..
run: cd samples/rust && cargo run && cargo test && cd ../..
2 changes: 1 addition & 1 deletion samples/python/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
def sample():
print("Dlccryptlib sample app, Python")

entropy_hex = "99d33a674ce99d33a674ce99d33a674c" # oil x 12
entropy_hex = "00000000000000000000000000000001" # abandon x 11 actual
network = "signet";

xpub = dlccryptlib_py.init_with_entropy(entropy_hex, network)
Expand Down
6 changes: 5 additions & 1 deletion samples/rust/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
///
/// Sample Rust program to use dlccryptlib.
///

#[cfg(test)]
mod test_lib;

use dlccryptlib;

fn main() {
println!("Dlccryptlib sample (Rust)");

let entropy_hex = "99d33a674ce99d33a674ce99d33a674c"; // oil x 12
let entropy_hex = "00000000000000000000000000000001"; // abandon x 11 actual
let network = "signet";

let xpub = dlccryptlib::init_with_entropy_intern(entropy_hex, network).unwrap();
Expand Down
54 changes: 54 additions & 0 deletions samples/rust/src/test_lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
///
/// Sample Rust program to use dlccryptlib.
///
use dlccryptlib;

const DUMMY_ENTROPY_STR: &str = "00000000000000000000000000000001";
const DUMMY_HASH07_STR: &str = "0000000000000000000000000000000000000000000000000000000000000007";
const NETWORK_SIGNET: &str = "signet";
const DEFAULT_NETWORK: &str = NETWORK_SIGNET;

#[test]
fn test_init_with_entropy() {
let xpub = dlccryptlib::init_with_entropy_intern(DUMMY_ENTROPY_STR, DEFAULT_NETWORK).unwrap();
assert_eq!(
xpub,
"tpubDCxVvuZwEu4oZypCT3pzos1MUoVJyjTHjfrhKFXNBkAEqBmkkzEb2dUgzpZmBWbd6wZnNmm3Ex2suMnEFUMmayH2a6S49R4pTnoQttGrxUm"
);
}

#[test]
fn test_get_public_key() {
let _xpub = dlccryptlib::init_with_entropy_intern(DUMMY_ENTROPY_STR, DEFAULT_NETWORK).unwrap();

let pubkey0 = dlccryptlib::get_public_key_intern(0).unwrap();
assert_eq!(
pubkey0.to_string(),
"031941e84b8d111e094aefc46e7181757c93a1da87c93ab519a40d9d765176e704"
);

let pubkey3 = dlccryptlib::get_public_key_intern(3).unwrap();
assert_eq!(
pubkey3.to_string(),
"02a9569875400df2b7af9360fc5025de31fcd48ca8b658d61e535c3ff2f55aa128"
);
}

#[test]
fn test_sign_hash_ecdsa() {
let _xpub = dlccryptlib::init_with_entropy_intern(DUMMY_ENTROPY_STR, DEFAULT_NETWORK).unwrap();

let pubkey3 = dlccryptlib::get_public_key_intern(3).unwrap();
assert_eq!(
pubkey3.to_string(),
"02a9569875400df2b7af9360fc5025de31fcd48ca8b658d61e535c3ff2f55aa128"
);

let hash = DUMMY_HASH07_STR;
let sig = dlccryptlib::sign_hash_ecdsa_intern(&hash, 3, &pubkey3).unwrap();

assert!(sig.len() >= 140 && sig.len() <= 146);

// negative test, wrong index
assert!(dlccryptlib::sign_hash_ecdsa_intern(&hash, 31, &pubkey3).is_err());
}