diff --git a/packages/Cargo.lock b/packages/Cargo.lock index 95646bc..52e0cd4 100644 --- a/packages/Cargo.lock +++ b/packages/Cargo.lock @@ -1833,7 +1833,7 @@ dependencies = [ [[package]] name = "sidan-csl-rs" -version = "0.5.2" +version = "0.5.3" dependencies = [ "cardano-serialization-lib", "cryptoxide", @@ -2387,7 +2387,7 @@ dependencies = [ [[package]] name = "whisky" -version = "0.5.2" +version = "0.5.3" dependencies = [ "async-trait", "cardano-serialization-lib", diff --git a/packages/sidan-csl-rs/Cargo.toml b/packages/sidan-csl-rs/Cargo.toml index b4dc1d4..8e4273e 100644 --- a/packages/sidan-csl-rs/Cargo.toml +++ b/packages/sidan-csl-rs/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sidan-csl-rs" -version = "0.5.2" +version = "0.5.3" edition = "2021" license = "Apache-2.0" description = "Wrapper around the cardano-serialization-lib for easier transaction building, heavily inspired by cardano-cli APIs" diff --git a/packages/sidan-csl-rs/src/core/utils/address.rs b/packages/sidan-csl-rs/src/core/utils/address.rs index 2658503..a99b12e 100644 --- a/packages/sidan-csl-rs/src/core/utils/address.rs +++ b/packages/sidan-csl-rs/src/core/utils/address.rs @@ -49,10 +49,16 @@ pub fn serialize_bech32_address(bech32_addr: String) -> SerializedAddress { .to_keyhash() .map(|stake_key_hash| stake_key_hash.to_hex()); + let csl_stake_key_script_hash = address + .stake_cred() + .to_scripthash() + .map(|stake_key_script_hash| stake_key_script_hash.to_hex()); + SerializedAddress::new( csl_key_hash.unwrap_or("".to_string()), csl_script_hash.unwrap_or("".to_string()), csl_stake_key_hash.unwrap_or("".to_string()), + csl_stake_key_script_hash.unwrap_or("".to_string()), ) } None => { @@ -75,6 +81,7 @@ pub fn serialize_bech32_address(bech32_addr: String) -> SerializedAddress { csl_key_hash.unwrap_or("".to_string()), csl_script_hash.unwrap_or("".to_string()), "".to_string(), + "".to_string(), ) } } @@ -115,14 +122,33 @@ pub fn parse_plutus_address_obj_to_bech32(plutus_data_address_obj: &str, network ["bytes"] .as_str() .unwrap(); - csl::BaseAddress::new( - network_id, - &csl_payment_credential, - &csl::Credential::from_keyhash(&csl::Ed25519KeyHash::from_hex(stake_key_hash).unwrap()), - ) - .to_address() - .to_bech32(None) - .unwrap() + if plutus_data_stake_key_obj["fields"][0]["fields"][0]["constructor"] + .as_u64() + .unwrap() + == 0 + { + csl::BaseAddress::new( + network_id, + &csl_payment_credential, + &csl::Credential::from_keyhash( + &csl::Ed25519KeyHash::from_hex(stake_key_hash).unwrap(), + ), + ) + .to_address() + .to_bech32(None) + .unwrap() + } else { + csl::BaseAddress::new( + network_id, + &csl_payment_credential, + &csl::Credential::from_scripthash( + &csl::ScriptHash::from_hex(stake_key_hash).unwrap(), + ), + ) + .to_address() + .to_bech32(None) + .unwrap() + } } else { csl::EnterpriseAddress::new(network_id, &csl_payment_credential) .to_address() diff --git a/packages/sidan-csl-rs/src/model/serialized_address.rs b/packages/sidan-csl-rs/src/model/serialized_address.rs index 3b8cc63..6c0b2e3 100644 --- a/packages/sidan-csl-rs/src/model/serialized_address.rs +++ b/packages/sidan-csl-rs/src/model/serialized_address.rs @@ -6,15 +6,22 @@ pub struct SerializedAddress { pub_key_hash: String, script_hash: String, stake_key_hash: String, + stake_key_script_hash: String, } #[wasm_bindgen] impl SerializedAddress { - pub fn new(pub_key_hash: String, script_hash: String, stake_key_hash: String) -> Self { + pub fn new( + pub_key_hash: String, + script_hash: String, + stake_key_hash: String, + stake_key_script_hash: String, + ) -> Self { Self { pub_key_hash, script_hash, stake_key_hash, + stake_key_script_hash, } } @@ -29,4 +36,8 @@ impl SerializedAddress { pub fn get_stake_key_hash(&self) -> String { self.stake_key_hash.clone() } + + pub fn get_stake_key_script_hash(&self) -> String { + self.stake_key_script_hash.clone() + } } diff --git a/packages/sidan-csl-rs/tests/address_tests.rs b/packages/sidan-csl-rs/tests/address_tests.rs index dab21e8..c1def53 100644 --- a/packages/sidan-csl-rs/tests/address_tests.rs +++ b/packages/sidan-csl-rs/tests/address_tests.rs @@ -31,7 +31,8 @@ mod address_tests { == SerializedAddress::new( "8f2ac4b2a57a90feb7717c7361c7043af6c3646e9db2b0e616482f73".to_string(), "".to_string(), - "039506b8e57e150bb66f6134f3264d50c3b70ce44d052f4485cf388f".to_string() + "039506b8e57e150bb66f6134f3264d50c3b70ce44d052f4485cf388f".to_string(), + "".to_string(), ) ); @@ -42,7 +43,8 @@ mod address_tests { == SerializedAddress::new( "".to_string(), "25b86eea84a44a3cf98bf470e2dafa02a8d95b81028c51583610297e".to_string(), - "5ca749261aa3b17aa2cd4b026bc6566c4b14421d6083edce64ffe5cb".to_string() + "5ca749261aa3b17aa2cd4b026bc6566c4b14421d6083edce64ffe5cb".to_string(), + "".to_string(), ) ); @@ -53,6 +55,7 @@ mod address_tests { == SerializedAddress::new( "5ca51b304b1f79d92eada8c58c513e969458dcd27ce4f5bc47823ffa".to_string(), "".to_string(), + "".to_string(), "".to_string() ) ); @@ -64,8 +67,21 @@ mod address_tests { == SerializedAddress::new( "36314aebecfbc929ee447dcb50fd690604eceae9403a298d9b1f9a54".to_string(), "".to_string(), - "75531fbe1e68b11e9a10dbbc5df889edea92325a85b758bbbf8735d9".to_string() + "75531fbe1e68b11e9a10dbbc5df889edea92325a85b758bbbf8735d9".to_string(), + "".to_string() + ) + ); + + let addr5 = "addr_test1xrqjazgu36v4e7jaz4r6eccyz09d9xyz0gvlhw82fx6xg6vx0j94wtj6ercvzj48g97tnjhvn50l2r5efamja2edd86ql04h5v"; + let addr5_result = serialize_bech32_address(addr5.to_string()); + assert!( + addr5_result + == SerializedAddress::new( + "".to_string(), + "c12e891c8e995cfa5d1547ace30413cad298827a19fbb8ea49b46469".to_string(), + "".to_string(), + "867c8b572e5ac8f0c14aa7417cb9caec9d1ff50e994f772eab2d69f4".to_string() ) - ) + ); } } diff --git a/packages/whisky/Cargo.toml b/packages/whisky/Cargo.toml index 2c6fa81..41db6d8 100644 --- a/packages/whisky/Cargo.toml +++ b/packages/whisky/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "whisky" -version = "0.5.2" +version = "0.5.3" edition = "2021" license = "Apache-2.0" description = "The Cardano Rust SDK, inspired by MeshJS" @@ -24,7 +24,7 @@ noop_proc_macro = "0.3.0" pallas-codec = "0.22.0" pallas-primitives = "0.22.0" pallas-traverse = "0.22.0" -sidan-csl-rs = { version = "=0.5.2", path = "../sidan-csl-rs" } +sidan-csl-rs = { version = "=0.5.3", path = "../sidan-csl-rs" } [profile.release] # Tell `rustc` to optimize for small code size.