-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: imkey support bitcoin psbt transaction[R2D2-11602] (#114)
* feat: add p2wpkhp2tr address generation * feat: add bitcoin Mixed signature function * test: modify p2wpkh test case * feat: add bitcoin p2wpkh sign * feat: add test case and add p2tr sign * test: add test case * test: modify btc test case * feat: code optimization * feat: modify display_addres and get_address * feat: add bitcoin p2tr transaction * test: add p2tr test case * test: add bitcoin transaction sign function test * feat: code optimization * feat: pass in the tweaked public key when signing * chore: code format * feat: add imKey PSBT feature code * feat: add p2wpkhp2tr address generation * feat: add bitcoin Mixed signature function * test: modify p2wpkh test case * feat: add bitcoin p2wpkh sign * feat: add test case and add p2tr sign * test: add test case * test: modify btc test case * feat: code optimization * feat: modify display_addres and get_address * feat: add bitcoin p2tr transaction * test: add p2tr test case * test: add bitcoin transaction sign function test * feat: code optimization * feat: pass in the tweaked public key when signing * chore: code format * chore: switch to staging env * feat: add imKey PSBT feature code * feat: derive_account and derive_sub_account support native segwit address and bech32 address * feat: add bitcoin psbt sign transaction * feat: add bitcoin p2tr script sign * fix: fix psbt legacy transaction bug * chore: psbt code optimized * fix: fix preview info calc error bug * fix: modify change path to account path * chore: code optimized * feat: psbt transaction support sign message * feat: add bip-322 sign message feature * feat: add bitcoin sign message api * chore: remove address verify function * chore: get_utxo_pub_key function removes the network param * chore: modify tcx version to 2.8.0 * chore: bip322 sign message add path check and code optimization * build: moify ios CI run-on version to macos-14 * fix: fix ios CI build error * fix: fix cargo check error * chore: optimization imKey public key conversion * chore: PubKeyParam removes isSegwit field
- Loading branch information
1 parent
4039e2f
commit e244c49
Showing
41 changed files
with
3,965 additions
and
892 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
2.7.4 | ||
2.8.0 |
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
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
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,124 @@ | ||
use super::Result; | ||
use anyhow::anyhow; | ||
|
||
pub trait ToHex { | ||
fn to_hex(&self) -> String; | ||
|
||
fn to_0x_hex(&self) -> String { | ||
format!("0x{}", self.to_hex()) | ||
} | ||
} | ||
|
||
pub trait FromHex | ||
where | ||
Self: Sized, | ||
{ | ||
fn from_hex<T: AsRef<[u8]>>(value: T) -> Result<Self>; | ||
|
||
fn from_0x_hex<T: AsRef<[u8]>>(value: T) -> Result<Self> { | ||
if value.as_ref().len() == 0 { | ||
return Ok(Self::from_hex("")?); | ||
} | ||
|
||
let bytes = value.as_ref(); | ||
Self::from_hex(&bytes[2..bytes.len()]) | ||
} | ||
|
||
fn from_hex_auto<T: AsRef<[u8]>>(value: T) -> Result<Self> { | ||
let bytes = value.as_ref(); | ||
if bytes.len() >= 2 && bytes[0] == b'0' && (bytes[1] == b'x' || bytes[1] == b'X') { | ||
Self::from_0x_hex(value) | ||
} else { | ||
Self::from_hex(value) | ||
} | ||
} | ||
} | ||
|
||
impl<T: AsRef<[u8]>> ToHex for T { | ||
fn to_hex(&self) -> String { | ||
hex::encode(self) | ||
} | ||
} | ||
|
||
impl ToHex for [u8] { | ||
fn to_hex(&self) -> String { | ||
hex::encode(self) | ||
} | ||
} | ||
|
||
impl FromHex for Vec<u8> { | ||
fn from_hex<T: AsRef<[u8]>>(value: T) -> Result<Self> { | ||
hex::decode(value).map_err(|e| anyhow!("{}", e.to_string())) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::{FromHex, ToHex}; | ||
#[test] | ||
fn test_to_hex() { | ||
let data = vec![0x01, 0x02, 0x03, 0x04]; | ||
assert_eq!(data.to_hex(), "01020304"); | ||
} | ||
|
||
#[test] | ||
fn test_to_hex_empty() { | ||
let data = vec![]; | ||
assert_eq!(data.to_hex(), ""); | ||
} | ||
|
||
#[test] | ||
fn test_to_hex_with_prefix_empty() { | ||
let data = vec![]; | ||
assert_eq!(data.to_0x_hex(), "0x"); | ||
} | ||
|
||
#[test] | ||
fn test_to_hex_from_slice() { | ||
let data = vec![0x01, 0x02, 0x03, 0x04]; | ||
assert_eq!(data[0..2].to_hex(), "0102"); | ||
} | ||
|
||
#[test] | ||
fn test_to_hex_from_fixed_array() { | ||
let data = [0x01, 0x02, 0x03, 0x04]; | ||
assert_eq!(data.to_hex(), "01020304"); | ||
} | ||
|
||
#[test] | ||
fn test_to_hex_with_prefix() { | ||
let data = vec![0x01, 0x02, 0x03, 0x04]; | ||
assert_eq!(data.to_0x_hex(), "0x01020304"); | ||
} | ||
|
||
#[test] | ||
fn test_from_hex() { | ||
let data = vec![0x01, 0x02, 0x03, 0x04]; | ||
assert_eq!(Vec::from_hex("01020304").unwrap(), data); | ||
} | ||
|
||
#[test] | ||
fn test_from_hex_with_prefix() { | ||
let value = "0x01020304"; | ||
assert_eq!(Vec::from_0x_hex(value).unwrap(), [0x01, 0x02, 0x03, 0x04]); | ||
} | ||
|
||
#[test] | ||
fn test_from_hex_with_prefix_error() { | ||
let value = "0x010203041"; | ||
assert!(Vec::from_0x_hex(value).is_err(),); | ||
} | ||
|
||
#[test] | ||
fn test_from_hex_auto() { | ||
assert_eq!( | ||
Vec::from_hex_auto("0x01020304").unwrap(), | ||
[0x01, 0x02, 0x03, 0x04] | ||
); | ||
|
||
assert_eq!( | ||
Vec::from_hex_auto("01020304").unwrap(), | ||
[0x01, 0x02, 0x03, 0x04] | ||
); | ||
} | ||
} |
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
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
Oops, something went wrong.