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

Support btc linking on staging #2334

Merged
merged 4 commits into from
Dec 15, 2023
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
1 change: 1 addition & 0 deletions primitives/core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub enum ErrorDetail {
VerifyEvmSignatureFailed,
RecoverEvmAddressFailed,
Web3NetworkOutOfBounds,
VerifyBitcoinSignatureFailed,
}

// We could have used Into<ErrorDetail>, but we want it to be more explicit, similar to `into_iter`
Expand Down
35 changes: 35 additions & 0 deletions primitives/core/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ pub enum Web3Network {
// evm
Ethereum,
Bsc,

// btc
Bitcoin,
}

impl Web3Network {
Expand All @@ -73,6 +76,7 @@ impl Web3Network {
Web3Network::SubstrateTestnet => "SubstrateTestnet",
Web3Network::Ethereum => "Ethereum",
Web3Network::Bsc => "Bsc",
Web3Network::Bitcoin => "Bitcoin",
}
}

Expand All @@ -89,6 +93,10 @@ impl Web3Network {
pub fn is_evm(&self) -> bool {
matches!(self, Self::Ethereum | Self::Bsc)
}

pub fn is_bitcoin(&self) -> bool {
matches!(self, Self::Bitcoin)
}
}

pub fn all_web3networks() -> Vec<Web3Network> {
Expand All @@ -103,6 +111,10 @@ pub fn all_evm_web3networks() -> Vec<Web3Network> {
Web3Network::iter().filter(|n| n.is_evm()).collect()
}

pub fn all_bitcoin_web3networks() -> Vec<Web3Network> {
Web3Network::iter().filter(|n| n.is_bitcoin()).collect()
}

#[cfg(test)]
mod tests {
use super::*;
Expand All @@ -128,6 +140,7 @@ mod tests {
Web3Network::SubstrateTestnet => false,
Web3Network::Ethereum => true,
Web3Network::Bsc => true,
Web3Network::Bitcoin => false,
}
)
})
Expand All @@ -148,6 +161,28 @@ mod tests {
Web3Network::SubstrateTestnet => true,
Web3Network::Ethereum => false,
Web3Network::Bsc => false,
Web3Network::Bitcoin => false,
}
)
})
}

#[test]
fn is_bitcoin_works() {
Web3Network::iter().for_each(|network| {
assert_eq!(
network.is_bitcoin(),
match network {
Web3Network::Polkadot => false,
Web3Network::Kusama => false,
Web3Network::Litentry => false,
Web3Network::Litmus => false,
Web3Network::LitentryRococo => false,
Web3Network::Khala => false,
Web3Network::SubstrateTestnet => false,
Web3Network::Ethereum => false,
Web3Network::Bsc => false,
Web3Network::Bitcoin => true,
}
)
})
Expand Down
2 changes: 1 addition & 1 deletion runtime/litentry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
impl_name: create_runtime_str!("litentry-parachain"),
authoring_version: 1,
// same versioning-mechanism as polkadot: use last digit for minor updates
spec_version: 9167,
spec_version: 9168,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down
2 changes: 1 addition & 1 deletion runtime/litmus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
impl_name: create_runtime_str!("litmus-parachain"),
authoring_version: 1,
// same versioning-mechanism as polkadot: use last digit for minor updates
spec_version: 9167,
spec_version: 9168,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down
2 changes: 1 addition & 1 deletion runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
impl_name: create_runtime_str!("rococo-parachain"),
authoring_version: 1,
// same versioning-mechanism as polkadot: use last digit for minor updates
spec_version: 9167,
spec_version: 9168,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down
12 changes: 4 additions & 8 deletions tee-worker/cli/src/base_cli/commands/litentry/link_identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ use substrate_api_client::{compose_extrinsic, CallIndex, UncheckedExtrinsicV4, X
pub struct LinkIdentityCommand {
/// AccountId in ss58check format
account: String,
/// Identity to be created
identity: String,
/// Identity to be created, in did form
did: String,
/// Shard identifier
shard: String,
}
Expand All @@ -57,14 +57,10 @@ impl LinkIdentityCommand {
let who = sr25519_core::Pair::from_string(&self.account, None).unwrap();
let chain_api = chain_api.set_signer(who.clone());

let identity: Result<Identity, _> = serde_json::from_str(self.identity.as_str());
if let Err(e) = identity {
warn!("Deserialize Identity error: {:?}", e.to_string());
return
}
let identity = Identity::from_did(self.did.as_str()).unwrap();

let tee_shielding_key = get_shielding_key(cli).unwrap();
let encrypted_identity = tee_shielding_key.encrypt(&identity.unwrap().encode()).unwrap();
let encrypted_identity = tee_shielding_key.encrypt(&identity.encode()).unwrap();

// TODO: the params are incorrect - and need to be reworked too
let vdata: Option<Vec<u8>> = None;
Expand Down
9 changes: 7 additions & 2 deletions tee-worker/core-primitives/substrate-sgx/sp-io/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,8 +668,13 @@ pub mod crypto {
sig: &[u8; 65],
msg: &[u8; 32],
) -> Result<[u8; 33], EcdsaVerifyError> {
warn!("crypto::secp256k1_ecdsa_recover unimplemented");
Ok([0; 33])
let rs = libsecp256k1::Signature::parse_standard_slice(&sig[0..64])
.map_err(|_| EcdsaVerifyError::BadRS)?;
let v = libsecp256k1::RecoveryId::parse(if sig[64] > 26 { sig[64] - 27 } else { sig[64] })
.map_err(|_| EcdsaVerifyError::BadV)?;
let pubkey = libsecp256k1::recover(&libsecp256k1::Message::parse(msg), &rs, &v)
.map_err(|_| EcdsaVerifyError::BadSignature)?;
Ok(pubkey.serialize_compressed())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ use crate::{
achainable::{query_lit_holding_amount, request_achainable_balance},
*,
};
use lc_credentials::{achainable::lit_holding_amount::AchainableLitHoldingAmountUpdate, litentry_profile::token_balance::TokenBalanceInfo};
use lc_credentials::{
achainable::lit_holding_amount::AchainableLitHoldingAmountUpdate,
litentry_profile::token_balance::TokenBalanceInfo,
};
use lc_data_providers::{
achainable_names::{AchainableNameAmountToken, GetAchainableName},
ETokenAddress, TokenFromString,
Expand Down
2 changes: 1 addition & 1 deletion tee-worker/litentry/core/credentials/src/achainable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
// You should have received a copy of the GNU General Public License
// along with Litentry. If not, see <https://www.gnu.org/licenses/>.

pub mod lit_holding_amount;
pub mod lit_holding_amount;
2 changes: 1 addition & 1 deletion tee-worker/litentry/core/credentials/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ pub use error::Error;
pub mod oneblock;
pub mod schema;

pub mod assertion_logic;
pub mod achainable;
pub mod assertion_logic;
use assertion_logic::{AssertionLogic, Op};
pub mod generic_discord_role;
pub mod litentry_profile;
Expand Down
1 change: 1 addition & 0 deletions tee-worker/litentry/core/data-providers/src/achainable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ pub fn web3_network_to_chain(network: &Web3Network) -> String {
Web3Network::SubstrateTestnet => "substrate_testnet".into(),
Web3Network::Ethereum => "ethereum".into(),
Web3Network::Bsc => "bsc".into(),
Web3Network::Bitcoin => "bitcoin".into(),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ pub fn verify(
return Err(Error::LinkIdentityFailed(ErrorDetail::VerifySubstrateSignatureFailed)),
Web3ValidationData::Evm(_) =>
return Err(Error::LinkIdentityFailed(ErrorDetail::VerifyEvmSignatureFailed)),
Web3ValidationData::Bitcoin(_) =>
return Err(Error::LinkIdentityFailed(ErrorDetail::VerifyBitcoinSignatureFailed)),
}
}

Expand Down
Loading