Skip to content

Commit

Permalink
Add const values from bitcoin and secp256k1
Browse files Browse the repository at this point in the history
  • Loading branch information
XuJiandong committed Jan 8, 2024
1 parent dd9f6a1 commit fcddadf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
7 changes: 0 additions & 7 deletions tests/omni_lock_rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ ckb-script = "0.100.0-rc2"
ckb-traits = "0.100.0-rc2"
ckb-types = "0.100.0-rc2"
ckb-chain-spec = "0.100.0-rc2"
# ckb-crypto = "0.40.0"
# ckb-error = "0.40.0"
# ckb-hash = "0.40.0"
# ckb-script = "0.40.0"
# ckb-traits = "0.40.0"
# ckb-types = "0.40.0"
# ckb-vm = "=0.19.3"
lazy_static = "1.3.0"
rand = "0.6.5"
sparse-merkle-tree = { git = "https://github.com/nervosnetwork/sparse-merkle-tree.git", rev = "2dce546"}
Expand Down
21 changes: 14 additions & 7 deletions tests/omni_lock_rust/tests/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ pub const ERROR_SUPPLY_AMOUNT: i8 = 91;
pub const ERROR_BURN: i8 = 92;
pub const ERROR_NO_INFO_CELL: i8 = 93;

// https://github.com/bitcoin-core/secp256k1/blob/d373bf6d08c82ac5496bf8103698c9f54d8d99d2/include/secp256k1.h#L219
pub const SECP256K1_TAG_PUBKEY_EVEN: u8 = 0x02;
pub const SECP256K1_TAG_PUBKEY_ODD: u8 = 0x03;
pub const SECP256K1_TAG_PUBKEY_UNCOMPRESSED: u8 = 0x04;
pub const SECP256K1_TAG_PUBKEY_HYBRID_EVEN: u8 = 0x06;
pub const SECP256K1_TAG_PUBKEY_HYBRID_ODD: u8 = 0x07;

pub const BITCOIN_V_TYPE_P2PKHUNCOMPRESSED: u8 = 27;
pub const BITCOIN_V_TYPE_P2PKHCOMPRESSED: u8 = 31;
pub const BITCOIN_V_TYPE_SEGWITP2SH: u8 = 35;
pub const BITCOIN_V_TYPE_SEGWITBECH32: u8 = 39;

lazy_static! {
pub static ref OMNI_LOCK: Bytes = Bytes::from(&include_bytes!("../../../build/omni_lock")[..]);
pub static ref SIMPLE_UDT: Bytes =
Expand Down Expand Up @@ -1146,11 +1158,6 @@ impl Default for MultisigTestConfig {
}
}

pub const BITCOIN_V_TYPE_P2PKHUNCOMPRESSED: u8 = 27;
pub const BITCOIN_V_TYPE_P2PKHCOMPRESSED: u8 = 31;
pub const BITCOIN_V_TYPE_SEGWITP2SH: u8 = 35;
pub const BITCOIN_V_TYPE_SEGWITBECH32: u8 = 39;

pub struct BitcoinConfig {
pub sign_vtype: u8,
pub pubkey_err: bool,
Expand All @@ -1176,7 +1183,7 @@ impl BitcoinConfig {
BITCOIN_V_TYPE_P2PKHUNCOMPRESSED => {
let mut pk_data = Vec::<u8>::new();
pk_data.resize(65, 0);
pk_data[0] = 4;
pk_data[0] = SECP256K1_TAG_PUBKEY_UNCOMPRESSED;
pk_data[1..].copy_from_slice(pubkey.as_bytes());

bitcoin_hash160(&pk_data)
Expand Down Expand Up @@ -1272,7 +1279,7 @@ impl EOSConfig {
let buf = match self.0.sign_vtype {
BITCOIN_V_TYPE_P2PKHUNCOMPRESSED => {
let mut temp: BytesMut = BytesMut::with_capacity(65);
temp.put_u8(4);
temp.put_u8(SECP256K1_TAG_PUBKEY_UNCOMPRESSED);
temp.put(Bytes::from(pubkey.as_bytes().to_vec()));
temp.freeze().to_vec()
}
Expand Down

0 comments on commit fcddadf

Please sign in to comment.