Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

package psbt and wif #107

Closed
wants to merge 7 commits into from
Closed
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
17 changes: 5 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.7.3
2.7.4
2 changes: 1 addition & 1 deletion token-core/tcx-btc-kin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ tcx-common = { path = "../tcx-common" }
hex = "=0.4.3"
base64 = "=0.13.1"

bitcoin = "=0.29.2"
bitcoin = {version = "=0.29.2", features = ["serde", "std", "secp-recovery"] }
secp256k1 = {version ="=0.24.3", features = ["rand", "recovery", "rand-std"] }
tiny-bip39 = "=1.0.0"
bitcoin_hashes = "=0.11.0"
Expand Down
10 changes: 10 additions & 0 deletions token-core/tcx-btc-kin/src/bch_sighash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,14 @@ impl TxSignatureHasher for BitcoinCashSighash {
) -> Result<TapSighashHash> {
Err(Error::UnsupportedTaproot.into())
}

fn taproot_script_spend_signature_hash(
&mut self,
input_index: usize,
prevouts: &Prevouts<TxOut>,
tap_leaf_hash: TapLeafHash,
sighash_type: SchnorrSighashType,
) -> Result<TapSighashHash> {
Err(Error::UnsupportedTaproot.into())
}
}
57 changes: 55 additions & 2 deletions token-core/tcx-btc-kin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub mod network;
pub mod signer;
pub mod transaction;

mod message;
mod psbt;

use core::result;
Expand All @@ -20,7 +21,6 @@ extern crate num_traits;

#[macro_use]
extern crate tcx_keystore;
extern crate core;

pub type Result<T> = result::Result<T, anyhow::Error>;

Expand Down Expand Up @@ -57,6 +57,9 @@ pub enum Error {
ConstructBchAddressFailed(String),
#[error("unsupported_taproot")]
UnsupportedTaproot,

#[error("missing_signature")]
MissingSignature,
}

pub mod bitcoin {
Expand All @@ -65,6 +68,10 @@ pub mod bitcoin {
pub type Address = crate::BtcKinAddress;
pub type TransactionInput = crate::transaction::BtcKinTxInput;
pub type TransactionOutput = crate::transaction::BtcKinTxOutput;

pub type MessageInput = crate::transaction::BtcMessageInput;

pub type MessageOutput = crate::transaction::BtcMessageOutput;
}

pub mod bitcoincash {
Expand All @@ -77,6 +84,10 @@ pub mod bitcoincash {
pub type TransactionInput = crate::transaction::BtcKinTxInput;

pub type TransactionOutput = crate::transaction::BtcKinTxOutput;

pub type MessageInput = crate::transaction::BtcMessageInput;

pub type MessageOutput = crate::transaction::BtcMessageOutput;
}

pub mod omni {
Expand All @@ -93,8 +104,10 @@ pub mod omni {

#[cfg(test)]
mod tests {
use tcx_constants::{TEST_MNEMONIC, TEST_PASSWORD};
use tcx_common::ToHex;
use tcx_constants::{CurveType, TEST_MNEMONIC, TEST_PASSWORD, TEST_WIF};
use tcx_keystore::{Keystore, Metadata};
use tcx_primitive::{PrivateKey, Secp256k1PrivateKey};

pub fn hd_keystore(mnemonic: &str) -> Keystore {
let mut keystore =
Expand All @@ -103,7 +116,47 @@ mod tests {
keystore
}

pub fn private_keystore(wif: &str) -> Keystore {
let sec_key = Secp256k1PrivateKey::from_wif(wif).unwrap();
let mut keystore = Keystore::from_private_key(
&sec_key.to_bytes().to_hex(),
TEST_PASSWORD,
CurveType::SECP256k1,
Metadata::default(),
None,
)
.unwrap();
keystore.unlock_by_password(TEST_PASSWORD).unwrap();
keystore
}

pub fn sample_hd_keystore() -> Keystore {
hd_keystore(TEST_MNEMONIC)
}

pub fn hex_keystore(hex: &str) -> Keystore {
let mut keystore = Keystore::from_private_key(
hex,
TEST_PASSWORD,
CurveType::SECP256k1,
Metadata::default(),
None,
)
.unwrap();
keystore.unlock_by_password(TEST_PASSWORD).unwrap();
keystore
}

pub fn wif_keystore(wif: &str) -> Keystore {
let hex = Secp256k1PrivateKey::from_wif(wif)
.unwrap()
.to_bytes()
.to_hex();

hex_keystore(&hex)
}

pub fn sample_wif_keystore() -> Keystore {
wif_keystore(TEST_WIF)
}
}
Loading
Loading