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
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "secp256k1"]
path = c/secp256k1
url = https://github.com/bitcoin-core/secp256k1.git

28 changes: 28 additions & 0 deletions src/descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,31 @@ pub mod tests {
assert_eq!(res, (pks, deriv));
}
}

#[cfg(all(test, feature = "rand"))]
mod keys_types {
use super::*;
use alloc::{string::String, vec::Vec};

const TEST_VECTORS_JSON: &str = include_str!("../test_vectors/keys_types.json");

#[derive(serde::Deserialize, serde::Serialize)]

struct TestVector {
description: String,
key: String,
expected: String,
}

#[test]
fn test_vector_keys_types() {
let vectors: Vec<TestVector> = serde_json::from_str(TEST_VECTORS_JSON).unwrap();

for v in vectors {
let dpk = DescriptorPublicKey::from_str(&v.key).expect(&v.description);
let pk = dpk_to_pk(&dpk);
let res = hex::encode(pk.serialize());
assert_eq!(v.expected, res, "{}", v.description);
}
}
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![no_std]
// #![no_std]
use crate::alloc::string::ToString;
extern crate alloc;
use alloc::{boxed::Box, string::String, vec, vec::Vec};
Expand Down
27 changes: 27 additions & 0 deletions test_vectors/keys_types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[
{
"description": "Xpub with origin and multipath",
"key": "[58b7f8dc/48'/1'/0'/2']tpubDEPBvXvhta3pjVaKokqC3eeMQnszj9ehFaA2zD5nSdkaccwGAizu8jVB2NeSpvmP2P52MBoZvNCixqXRJnTyXx51FQzARR63tjxQSyP3Btw/<0;1>/*",
"expected": "03ebd252ca0877aae09b9d058219682775aa3cbcd049c12f07832f2cf6a3b51708"
},
{
"description": "Xpub with origin and w/o multipath",
"key": "[d4ab66f1/48'/1'/1'/2']tpubDFTxBKyUCgkwp5enwZh3t2FJ5AMJqmCWoh1NRT13qNYQb1iKTUrAG6u5gpsDYhG8cZGXouYWuQtzcuSVjPStTc4dwU6JqPMFtgaLGvSQXhi",
"expected": "028e886919a6b72579a28bd292505d2afd41c1b5012414c5e24d7b59f4abdfc0ce"
},
{
"description": "Compressed public key",
"key": "02ebd252ca0877aae09b9d058219682775aa3cbcd049c12f07832f2cf6a3b51708",
"expected": "02ebd252ca0877aae09b9d058219682775aa3cbcd049c12f07832f2cf6a3b51708"
},
{
"description": "X only public key",
"key": "ebd252ca0877aae09b9d058219682775aa3cbcd049c12f07832f2cf6a3b51708",
"expected": "02ebd252ca0877aae09b9d058219682775aa3cbcd049c12f07832f2cf6a3b51708"
},
{
"description": "Uncompressed public key",
"key": "04ebd252ca0877aae09b9d058219682775aa3cbcd049c12f07832f2cf6a3b517089e956909c4c07e8529f45f3ff8904d28df5a181619e21bdf748a896322530039",
"expected": "03ebd252ca0877aae09b9d058219682775aa3cbcd049c12f07832f2cf6a3b51708"
}
]
Loading