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

Add Cardano Rust support #144

Merged
merged 5 commits into from
Oct 13, 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
16 changes: 14 additions & 2 deletions rust/apps/aptos/Cargo.lock

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

26 changes: 24 additions & 2 deletions rust/apps/bitcoin/Cargo.lock

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

9 changes: 6 additions & 3 deletions rust/apps/cardano/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,16 @@ mod tests {
let entropy = hex::decode("00000000000000000000000000000000").unwrap();
let spend_key =
keystore::algorithms::ed25519::bip32_ed25519::get_extended_public_key_by_entropy(
&path.to_string(),
entropy.as_slice(),
b"",
&path.to_string(),
)
.unwrap();
let stake_key =
keystore::algorithms::ed25519::bip32_ed25519::get_extended_public_key_by_entropy(
&path2.to_string(),
entropy.as_slice(),
b"",
&path2.to_string(),
)
.unwrap();
let spend = blake2b_224(spend_key.public_key_bytes());
Expand Down Expand Up @@ -139,8 +141,9 @@ mod tests {
let entropy = hex::decode("00000000000000000000000000000000").unwrap();
let xpub =
keystore::algorithms::ed25519::bip32_ed25519::get_extended_public_key_by_entropy(
&path.to_string(),
entropy.as_slice(),
b"",
&path.to_string(),
)
.unwrap();
{
Expand Down
19 changes: 14 additions & 5 deletions rust/apps/cardano/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ pub fn check_tx(tx: Vec<u8>, context: ParseContext) -> R<()> {
ParsedCardanoTx::verify(cardano_tx, context)
}

pub fn sign_tx(tx: Vec<u8>, context: ParseContext, entropy: &[u8]) -> R<Vec<u8>> {
pub fn sign_tx(
tx: Vec<u8>,
context: ParseContext,
entropy: &[u8],
passphrase: &[u8],
) -> R<Vec<u8>> {
let cardano_tx = cardano_serialization_lib::Transaction::from_bytes(tx)?;
let hash = blake2b_256(cardano_tx.body().to_bytes().as_ref());
let mut witness_set = cardano_serialization_lib::TransactionWitnessSet::new();
Expand All @@ -31,15 +36,17 @@ pub fn sign_tx(tx: Vec<u8>, context: ParseContext, entropy: &[u8]) -> R<Vec<u8>>
.map(|v| {
let pubkey =
keystore::algorithms::ed25519::bip32_ed25519::get_extended_public_key_by_entropy(
&v.get_path().to_string(),
entropy,
passphrase,
&v.get_path().to_string(),
)
.map(|v| v.public_key())
.map_err(|e| CardanoError::SigningFailed(e.to_string()));
let signature = keystore::algorithms::ed25519::bip32_ed25519::sign_message_by_entropy(
entropy,
passphrase,
&hash,
&v.get_path().to_string(),
entropy,
)
.map_err(|e| CardanoError::SigningFailed(e.to_string()));
pubkey.and_then(|_pubkey| signature.map(|_signature| (_pubkey, _signature)))
Expand All @@ -55,15 +62,17 @@ pub fn sign_tx(tx: Vec<u8>, context: ParseContext, entropy: &[u8]) -> R<Vec<u8>>
.map(|v| {
let pubkey =
keystore::algorithms::ed25519::bip32_ed25519::get_extended_public_key_by_entropy(
&v.get_path().to_string(),
entropy,
passphrase,
&v.get_path().to_string(),
)
.map(|v| v.public_key())
.map_err(|e| CardanoError::SigningFailed(e.to_string()));
let signature = keystore::algorithms::ed25519::bip32_ed25519::sign_message_by_entropy(
entropy,
passphrase,
&hash,
&v.get_path().to_string(),
entropy,
)
.map_err(|e| CardanoError::SigningFailed(e.to_string()));
pubkey.and_then(|v| signature.map(|_v| (v, _v)))
Expand Down
26 changes: 24 additions & 2 deletions rust/apps/cosmos/Cargo.lock

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

26 changes: 24 additions & 2 deletions rust/apps/ethereum/Cargo.lock

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

Loading
Loading