diff --git a/chain/rust/src/assets/mod.rs b/chain/rust/src/assets/mod.rs index adc3911b..1a6aee2f 100644 --- a/chain/rust/src/assets/mod.rs +++ b/chain/rust/src/assets/mod.rs @@ -12,6 +12,7 @@ use cml_core::error::*; use std::convert::TryFrom; +/// Use TryFrom<&str> / TryInto<&str> for utf8 text conversion and RawBytesEncoding for direct bytes access #[derive(Clone, Debug, derivative::Derivative)] #[derivative(Eq, PartialEq, Ord, PartialOrd, Hash)] pub struct AssetName { @@ -26,10 +27,6 @@ pub struct AssetName { } impl AssetName { - pub fn get(&self) -> &Vec { - &self.inner - } - pub fn new(inner: Vec) -> Result { if inner.len() > 32 { return Err(DeserializeError::new( diff --git a/chain/rust/src/assets/utils.rs b/chain/rust/src/assets/utils.rs index c3d6a56f..39d83b19 100644 --- a/chain/rust/src/assets/utils.rs +++ b/chain/rust/src/assets/utils.rs @@ -51,7 +51,17 @@ impl<'a> TryInto<&'a str> for &'a AssetName { type Error = std::str::Utf8Error; fn try_into(self) -> Result<&'a str, Self::Error> { - std::str::from_utf8(self.get()) + std::str::from_utf8(self.to_raw_bytes()) + } +} + +impl RawBytesEncoding for AssetName { + fn to_raw_bytes(&self) -> &[u8] { + self.inner.as_ref() + } + + fn from_raw_bytes(bytes: &[u8]) -> Result { + Self::new(bytes.to_vec()) } } @@ -71,7 +81,7 @@ impl std::fmt::Debug for AssetBundle { for (pid, assets) in self.0.iter() { let pid_hex = hex::encode(pid.to_raw_bytes()); for (an, val) in assets.iter() { - let an_hex = hex::encode(an.get()); + let an_hex = hex::encode(an.to_raw_bytes()); let an_name = if an_hex.len() > 8 { format!( "{}..{}", diff --git a/chain/rust/src/genesis/byron/parse.rs b/chain/rust/src/genesis/byron/parse.rs index 1ace4de7..ddbedc88 100644 --- a/chain/rust/src/genesis/byron/parse.rs +++ b/chain/rust/src/genesis/byron/parse.rs @@ -3,6 +3,7 @@ use base64::{ Engine, }; use cbor_event::cbor; +use cml_core::DeserializeError; use cml_crypto::{CryptoError, RawBytesEncoding}; use serde_json; use std::collections::BTreeMap; @@ -29,6 +30,8 @@ pub enum GenesisJSONError { Serde(#[from] serde_json::Error), #[error("Crypto: {0:?}")] CryptoError(#[from] CryptoError), + #[error("Deserialize: {0:?}")] + DeserializeError(#[from] DeserializeError), #[error("Base64: {0:?}")] Base64(#[from] base64::DecodeError), #[error("ParseInt: {0:?}")] diff --git a/chain/rust/src/plutus/mod.rs b/chain/rust/src/plutus/mod.rs index e1941b42..b815ed90 100644 --- a/chain/rust/src/plutus/mod.rs +++ b/chain/rust/src/plutus/mod.rs @@ -244,10 +244,6 @@ pub struct PlutusV1Script { } impl PlutusV1Script { - pub fn get(&self) -> &Vec { - &self.inner - } - pub fn new(inner: Vec) -> Self { Self { inner, @@ -317,10 +313,6 @@ pub struct PlutusV2Script { } impl PlutusV2Script { - pub fn get(&self) -> &Vec { - &self.inner - } - pub fn new(inner: Vec) -> Self { Self { inner, @@ -390,10 +382,6 @@ pub struct PlutusV3Script { } impl PlutusV3Script { - pub fn get(&self) -> &Vec { - &self.inner - } - pub fn new(inner: Vec) -> Self { Self { inner, diff --git a/chain/rust/src/plutus/utils.rs b/chain/rust/src/plutus/utils.rs index ae228c23..300d4e63 100644 --- a/chain/rust/src/plutus/utils.rs +++ b/chain/rust/src/plutus/utils.rs @@ -452,19 +452,49 @@ impl From for PlutusScript { impl PlutusV1Script { pub fn hash(&self) -> ScriptHash { - hash_script(ScriptHashNamespace::PlutusV1, self.get()) + hash_script(ScriptHashNamespace::PlutusV1, self.to_raw_bytes()) } } impl PlutusV2Script { pub fn hash(&self) -> ScriptHash { - hash_script(ScriptHashNamespace::PlutusV2, self.get()) + hash_script(ScriptHashNamespace::PlutusV2, self.to_raw_bytes()) } } impl PlutusV3Script { pub fn hash(&self) -> ScriptHash { - hash_script(ScriptHashNamespace::PlutusV3, self.get()) + hash_script(ScriptHashNamespace::PlutusV3, self.to_raw_bytes()) + } +} + +impl RawBytesEncoding for PlutusV1Script { + fn to_raw_bytes(&self) -> &[u8] { + self.inner.as_ref() + } + + fn from_raw_bytes(bytes: &[u8]) -> Result { + Ok(Self::new(bytes.to_vec())) + } +} + +impl RawBytesEncoding for PlutusV2Script { + fn to_raw_bytes(&self) -> &[u8] { + self.inner.as_ref() + } + + fn from_raw_bytes(bytes: &[u8]) -> Result { + Ok(Self::new(bytes.to_vec())) + } +} + +impl RawBytesEncoding for PlutusV3Script { + fn to_raw_bytes(&self) -> &[u8] { + self.inner.as_ref() + } + + fn from_raw_bytes(bytes: &[u8]) -> Result { + Ok(Self::new(bytes.to_vec())) } } diff --git a/chain/wasm/src/assets/mod.rs b/chain/wasm/src/assets/mod.rs index 62966512..b946a230 100644 --- a/chain/wasm/src/assets/mod.rs +++ b/chain/wasm/src/assets/mod.rs @@ -18,10 +18,3 @@ pub struct AssetName(cml_chain::assets::AssetName); impl_wasm_cbor_json_api!(AssetName); impl_wasm_conversions!(cml_chain::assets::AssetName, AssetName); - -#[wasm_bindgen] -impl AssetName { - pub fn get(&self) -> Vec { - self.0.get().clone() - } -} diff --git a/chain/wasm/src/assets/utils.rs b/chain/wasm/src/assets/utils.rs index b5393091..8fb40e6b 100644 --- a/chain/wasm/src/assets/utils.rs +++ b/chain/wasm/src/assets/utils.rs @@ -6,7 +6,9 @@ use std::{ use crate::{assets::AssetName, AssetNameList, MapAssetNameToNonZeroInt64, PolicyId, PolicyIdList}; use wasm_bindgen::{prelude::wasm_bindgen, JsError, JsValue}; -use cml_core_wasm::{impl_wasm_cbor_json_api, impl_wasm_conversions, impl_wasm_map}; +use cml_core_wasm::{ + impl_raw_bytes_api, impl_wasm_cbor_json_api, impl_wasm_conversions, impl_wasm_map, +}; use super::Coin; @@ -25,15 +27,6 @@ impl_wasm_map!( #[wasm_bindgen] impl AssetName { - /** - * Create an AssetName from raw bytes. 64 byte maximum. - */ - pub fn from_bytes(bytes: Vec) -> Result { - cml_chain::assets::AssetName::try_from(bytes) - .map(Into::into) - .map_err(Into::into) - } - /** * Create an AssetName from utf8 string. 64 byte (not char!) maximum. */ @@ -55,6 +48,8 @@ impl AssetName { } } +impl_raw_bytes_api!(cml_chain::assets::AssetName, AssetName); + #[derive(Clone, Debug)] #[wasm_bindgen] pub struct MultiAsset(cml_chain::assets::MultiAsset); diff --git a/chain/wasm/src/plutus/mod.rs b/chain/wasm/src/plutus/mod.rs index 33df2ea2..58d3db19 100644 --- a/chain/wasm/src/plutus/mod.rs +++ b/chain/wasm/src/plutus/mod.rs @@ -224,13 +224,6 @@ impl_wasm_cbor_json_api!(PlutusV1Script); impl_wasm_conversions!(cml_chain::plutus::PlutusV1Script, PlutusV1Script); -#[wasm_bindgen] -impl PlutusV1Script { - pub fn get(&self) -> Vec { - self.0.get().clone() - } -} - #[derive(Clone, Debug)] #[wasm_bindgen] pub struct PlutusV2Script(cml_chain::plutus::PlutusV2Script); @@ -239,13 +232,6 @@ impl_wasm_cbor_json_api!(PlutusV2Script); impl_wasm_conversions!(cml_chain::plutus::PlutusV2Script, PlutusV2Script); -#[wasm_bindgen] -impl PlutusV2Script { - pub fn get(&self) -> Vec { - self.0.get().clone() - } -} - #[derive(Clone, Debug)] #[wasm_bindgen] pub struct PlutusV3Script(cml_chain::plutus::PlutusV3Script); @@ -254,13 +240,6 @@ impl_wasm_cbor_json_api!(PlutusV3Script); impl_wasm_conversions!(cml_chain::plutus::PlutusV3Script, PlutusV3Script); -#[wasm_bindgen] -impl PlutusV3Script { - pub fn get(&self) -> Vec { - self.0.get().clone() - } -} - #[derive(Clone, Debug)] #[wasm_bindgen] pub struct RedeemerKey(cml_chain::plutus::RedeemerKey); diff --git a/chain/wasm/src/plutus/utils.rs b/chain/wasm/src/plutus/utils.rs index e2ca0103..2b458235 100644 --- a/chain/wasm/src/plutus/utils.rs +++ b/chain/wasm/src/plutus/utils.rs @@ -3,7 +3,9 @@ use crate::{ LegacyRedeemerList, PlutusDataList, }; use cml_chain::plutus::Language; -use cml_core_wasm::{impl_wasm_cbor_api, impl_wasm_cbor_json_api, impl_wasm_conversions}; +use cml_core_wasm::{ + impl_raw_bytes_api, impl_wasm_cbor_api, impl_wasm_cbor_json_api, impl_wasm_conversions, +}; use cml_crypto_wasm::ScriptHash; use wasm_bindgen::prelude::{wasm_bindgen, JsError, JsValue}; @@ -152,6 +154,19 @@ impl PlutusV2Script { } } +#[wasm_bindgen] +impl PlutusV3Script { + pub fn hash(&self) -> ScriptHash { + self.0.hash().into() + } +} + +impl_raw_bytes_api!(cml_chain::plutus::PlutusV1Script, PlutusV1Script); + +impl_raw_bytes_api!(cml_chain::plutus::PlutusV2Script, PlutusV2Script); + +impl_raw_bytes_api!(cml_chain::plutus::PlutusV3Script, PlutusV3Script); + #[wasm_bindgen] impl Redeemers { pub fn to_flat_format(&self) -> LegacyRedeemerList { diff --git a/cip25/rust/src/utils.rs b/cip25/rust/src/utils.rs index 2b61f379..1df70073 100644 --- a/cip25/rust/src/utils.rs +++ b/cip25/rust/src/utils.rs @@ -7,7 +7,6 @@ pub use cml_chain::{ PolicyId, }; pub use cml_core::{error::*, serialization::*}; -use cml_crypto::RawBytesEncoding; use std::io::{BufRead, Seek, SeekFrom, Write}; use crate::{CIP25ChunkableString, CIP25Metadata, CIP25MetadataDetails, CIP25String64}; @@ -251,7 +250,7 @@ impl CIP25LabelMetadata { details: CIP25MetadataDetails, ) -> Result, CIP25Error> { if self.version == CIP25Version::V1 { - if let Err(e) = String::from_utf8(asset_name.get().clone()) { + if let Err(e) = String::from_utf8(asset_name.to_raw_bytes().to_vec()) { return Err(CIP25Error::Version1NonStringAsset(asset_name, e)); } } @@ -296,7 +295,8 @@ impl cbor_event::se::Serialize for CIP25LabelMetadata { for (asset_name, details) in assets.iter() { // hand-edit: write as string // note: this invariant is checked during setting and data is private - let asset_name_str = String::from_utf8(asset_name.get().clone()).unwrap(); + let asset_name_str = + String::from_utf8(asset_name.to_raw_bytes().to_vec()).unwrap(); serializer.write_text(asset_name_str)?; details.serialize(serializer)?; } @@ -313,7 +313,7 @@ impl cbor_event::se::Serialize for CIP25LabelMetadata { serializer.write_map(cbor_event::Len::Len(assets.len() as u64))?; for (asset_name, details) in assets.iter() { // hand-edit: write bytes - serializer.write_bytes(asset_name.get())?; + serializer.write_bytes(asset_name.to_raw_bytes())?; details.serialize(serializer)?; } diff --git a/core/rust/src/serialization.rs b/core/rust/src/serialization.rs index 18f92a2c..0249c440 100644 --- a/core/rust/src/serialization.rs +++ b/core/rust/src/serialization.rs @@ -288,3 +288,24 @@ impl FromBytes for T { Self::deserialize(&mut raw).map_err(Into::into) } } +pub trait RawBytesEncoding { + fn to_raw_bytes(&self) -> &[u8]; + + fn from_raw_bytes(bytes: &[u8]) -> Result + where + Self: Sized; + + fn to_raw_hex(&self) -> String { + hex::encode(self.to_raw_bytes()) + } + + fn from_raw_hex(hex_str: &str) -> Result + where + Self: Sized, + { + let bytes = hex::decode(hex_str).map_err(|e| { + DeserializeError::from(DeserializeFailure::InvalidStructure(Box::new(e))) + })?; + Self::from_raw_bytes(bytes.as_ref()) + } +} diff --git a/core/wasm/src/lib.rs b/core/wasm/src/lib.rs index c3295315..aaabee57 100644 --- a/core/wasm/src/lib.rs +++ b/core/wasm/src/lib.rs @@ -2,6 +2,9 @@ use wasm_bindgen::prelude::{wasm_bindgen, JsValue}; use cml_core::serialization::{Deserialize, Serialize}; +// re-export to make macros easier to use +pub use cml_core::serialization::RawBytesEncoding; + #[macro_use] pub mod wasm_wrappers; diff --git a/core/wasm/src/wasm_wrappers.rs b/core/wasm/src/wasm_wrappers.rs index aa0ae9f1..2840bcb2 100644 --- a/core/wasm/src/wasm_wrappers.rs +++ b/core/wasm/src/wasm_wrappers.rs @@ -550,3 +550,46 @@ macro_rules! impl_wasm_json_api { } }; } + +#[macro_export] +macro_rules! impl_raw_bytes_api { + ($rust:ty, $wasm:ident) => { + #[wasm_bindgen] + impl $wasm { + /** + * Direct raw bytes without any CBOR structure + */ + pub fn to_raw_bytes(&self) -> Vec { + use cml_core_wasm::RawBytesEncoding; + self.0.to_raw_bytes().to_vec() + } + + /** + * Parse from the direct raw bytes, without any CBOR structure + */ + pub fn from_raw_bytes(bytes: &[u8]) -> Result<$wasm, wasm_bindgen::JsError> { + use cml_core_wasm::RawBytesEncoding; + <$rust>::from_raw_bytes(bytes).map(Self).map_err(Into::into) + } + + /** + * Direct raw bytes without any CBOR structure, as a hex-encoded string + */ + pub fn to_hex(&self) -> String { + use cml_core_wasm::RawBytesEncoding; + self.0.to_raw_hex() + } + + /** + * Parse from a hex string of the direct raw bytes, without any CBOR structure + */ + pub fn from_hex(input: &str) -> Result<$wasm, wasm_bindgen::JsError> { + use cml_core_wasm::RawBytesEncoding; + <$rust>::from_raw_hex(input) + .map(Into::into) + .map(Self) + .map_err(Into::into) + } + } + }; +} diff --git a/crypto/rust/src/lib.rs b/crypto/rust/src/lib.rs index cea53404..bda9bfd7 100644 --- a/crypto/rust/src/lib.rs +++ b/crypto/rust/src/lib.rs @@ -2,7 +2,7 @@ use crate::chain_crypto::bech32::Bech32; pub use cml_core::{ error::{DeserializeError, DeserializeFailure}, - serialization::{Deserialize, Serialize, StringEncoding}, + serialization::{Deserialize, RawBytesEncoding, Serialize, StringEncoding}, }; use cryptoxide::blake2b::Blake2b; pub use derivative::Derivative; @@ -22,26 +22,6 @@ pub mod typed_bytes; #[macro_use] extern crate cfg_if; -pub trait RawBytesEncoding { - fn to_raw_bytes(&self) -> &[u8]; - - fn from_raw_bytes(bytes: &[u8]) -> Result - where - Self: Sized; - - fn to_raw_hex(&self) -> String { - hex::encode(self.to_raw_bytes()) - } - - fn from_raw_hex(hex_str: &str) -> Result - where - Self: Sized, - { - let bytes = hex::decode(hex_str)?; - Self::from_raw_bytes(bytes.as_ref()) - } -} - #[derive(Debug, thiserror::Error)] pub enum CryptoError { #[error("Bech32: {0}")] @@ -124,7 +104,7 @@ impl Bip32PrivateKey { buf[0..64].clone_from_slice(&bytes[0..64]); buf[64..96].clone_from_slice(&bytes[96..128]); - Bip32PrivateKey::from_raw_bytes(&buf) + Bip32PrivateKey::from_raw_bytes(&buf).map_err(Into::into) } /// see from_128_xprv pub fn to_128_xprv(&self) -> Vec { @@ -181,9 +161,9 @@ impl RawBytesEncoding for Bip32PrivateKey { self.0.as_ref() } - fn from_raw_bytes(bytes: &[u8]) -> Result { + fn from_raw_bytes(bytes: &[u8]) -> Result { chain_crypto::SecretKey::::from_binary(bytes) - .map_err(Into::into) + .map_err(|e| DeserializeFailure::InvalidStructure(Box::new(e)).into()) .map(Bip32PrivateKey) } } @@ -248,9 +228,9 @@ impl RawBytesEncoding for Bip32PublicKey { self.0.as_ref() } - fn from_raw_bytes(bytes: &[u8]) -> Result { + fn from_raw_bytes(bytes: &[u8]) -> Result { chain_crypto::PublicKey::::from_binary(bytes) - .map_err(Into::into) + .map_err(|e| DeserializeFailure::InvalidStructure(Box::new(e)).into()) .map(Bip32PublicKey) } } @@ -339,8 +319,10 @@ impl RawBytesEncoding for PrivateKey { } } - fn from_raw_bytes(bytes: &[u8]) -> Result { - Self::from_normal_bytes(bytes).or_else(|_| Self::from_extended_bytes(bytes)) + fn from_raw_bytes(bytes: &[u8]) -> Result { + Self::from_normal_bytes(bytes) + .or_else(|_| Self::from_extended_bytes(bytes)) + .map_err(|e| DeserializeFailure::InvalidStructure(Box::new(e)).into()) } } @@ -387,9 +369,9 @@ impl RawBytesEncoding for PublicKey { self.0.as_ref() } - fn from_raw_bytes(bytes: &[u8]) -> Result { + fn from_raw_bytes(bytes: &[u8]) -> Result { chain_crypto::PublicKey::from_binary(bytes) - .map_err(Into::into) + .map_err(|e| DeserializeFailure::InvalidStructure(Box::new(e)).into()) .map(PublicKey) } } @@ -429,10 +411,10 @@ macro_rules! impl_signature { self.0.as_ref() } - fn from_raw_bytes(bytes: &[u8]) -> Result { + fn from_raw_bytes(bytes: &[u8]) -> Result { chain_crypto::Signature::from_binary(bytes.as_ref()) .map(Self) - .map_err(Into::into) + .map_err(|e| DeserializeFailure::InvalidStructure(Box::new(e)).into()) } } @@ -528,8 +510,10 @@ macro_rules! impl_hash_type { hex::encode(&self.0.as_ref()) } - pub fn from_hex(input: &str) -> Result { - let hex_bytes = hex::decode(input)?; + pub fn from_hex(input: &str) -> Result { + let hex_bytes = hex::decode(input).map_err(|e| { + DeserializeError::from(DeserializeFailure::InvalidStructure(Box::new(e))) + })?; Self::from_raw_bytes(&hex_bytes) } } @@ -557,7 +541,7 @@ macro_rules! impl_hash_type { self.0.as_ref() } - fn from_raw_bytes(bytes: &[u8]) -> Result { + fn from_raw_bytes(bytes: &[u8]) -> Result { use std::convert::TryInto; match bytes.len() { $byte_count => Ok($name(bytes[..$byte_count].try_into().unwrap())), @@ -570,8 +554,7 @@ macro_rules! impl_hash_type { Err(DeserializeError::new( stringify!($name), DeserializeFailure::CBOR(cbor_error), - ) - .into()) + )) } } } @@ -652,10 +635,10 @@ impl RawBytesEncoding for LegacyDaedalusPrivateKey { self.0.as_ref() } - fn from_raw_bytes(bytes: &[u8]) -> Result { + fn from_raw_bytes(bytes: &[u8]) -> Result { chain_crypto::SecretKey::::from_binary(bytes) .map(LegacyDaedalusPrivateKey) - .map_err(|e| e.into()) + .map_err(|e| DeserializeFailure::InvalidStructure(Box::new(e)).into()) } } diff --git a/crypto/wasm/Cargo.toml b/crypto/wasm/Cargo.toml index 9cc87314..f6b14588 100644 --- a/crypto/wasm/Cargo.toml +++ b/crypto/wasm/Cargo.toml @@ -14,6 +14,7 @@ keywords = ["cardano"] crate-type = ["cdylib", "rlib"] [dependencies] +cml-core-wasm = { path = "../../core/wasm", version = "5.3.1" } cml-crypto = { path = "../rust", version = "5.3.1" } cbor_event = "2.2.0" wasm-bindgen = { version = "0.2.87" } diff --git a/crypto/wasm/src/lib.rs b/crypto/wasm/src/lib.rs index 358c7848..4f017bba 100644 --- a/crypto/wasm/src/lib.rs +++ b/crypto/wasm/src/lib.rs @@ -333,39 +333,20 @@ macro_rules! impl_signature { #[wasm_bindgen] impl $name { - pub fn to_raw_bytes(&self) -> Vec { - self.0.to_raw_bytes().to_vec() - } - pub fn to_bech32(&self) -> String { self.0.to_bech32() } - pub fn to_hex(&self) -> String { - self.0.to_raw_hex() - } - - pub fn from_bech32(bech32_str: &str) -> Result<$name, JsError> { + pub fn from_bech32(bech32_str: &str) -> Result<$name, wasm_bindgen::JsError> { cml_crypto::$name::from_bech32(bech32_str) .map(Into::into) .map(Self) .map_err(Into::into) } - - pub fn from_hex(input: &str) -> Result<$name, JsError> { - cml_crypto::$name::from_raw_hex(input) - .map(Into::into) - .map(Self) - .map_err(Into::into) - } - - pub fn from_raw_bytes(bytes: &[u8]) -> Result<$name, JsError> { - cml_crypto::$name::from_raw_bytes(bytes) - .map(Self) - .map_err(Into::into) - } } + cml_core_wasm::impl_raw_bytes_api!(cml_crypto::$name, $name); + impl From for $name { fn from(inner: cml_crypto::$name) -> Self { Self(inner) @@ -397,11 +378,6 @@ macro_rules! impl_hash_type_ext { #[wasm_bindgen::prelude::wasm_bindgen] impl $wasm_name { - pub fn to_raw_bytes(&self) -> Vec { - use cml_crypto::RawBytesEncoding; - self.0.to_raw_bytes().to_vec() - } - pub fn to_bech32( &self, prefix: &str, @@ -409,11 +385,6 @@ macro_rules! impl_hash_type_ext { self.0.to_bech32(prefix).map_err(Into::into) } - pub fn to_hex(&self) -> String { - use cml_crypto::RawBytesEncoding; - self.0.to_raw_hex() - } - pub fn from_bech32( bech32_str: &str, ) -> Result<$wasm_name, wasm_bindgen::prelude::JsError> { @@ -422,22 +393,6 @@ macro_rules! impl_hash_type_ext { .map(Self) .map_err(Into::into) } - - pub fn from_hex(input: &str) -> Result<$wasm_name, wasm_bindgen::prelude::JsError> { - use cml_crypto::RawBytesEncoding; - <$rust_name>::from_raw_hex(input) - .map(Self) - .map_err(Into::into) - } - - pub fn from_raw_bytes( - bytes: &[u8], - ) -> Result<$wasm_name, wasm_bindgen::prelude::JsError> { - use cml_crypto::RawBytesEncoding; - <$rust_name>::from_raw_bytes(bytes) - .map(Self) - .map_err(Into::into) - } } impl From<$rust_name> for $wasm_name { @@ -457,6 +412,8 @@ macro_rules! impl_hash_type_ext { &self.0 } } + + cml_core_wasm::impl_raw_bytes_api!($rust_name, $wasm_name); }; } diff --git a/multi-era/rust/src/babbage/utils.rs b/multi-era/rust/src/babbage/utils.rs index 9461402e..cd45180c 100644 --- a/multi-era/rust/src/babbage/utils.rs +++ b/multi-era/rust/src/babbage/utils.rs @@ -194,7 +194,8 @@ impl Serialize for BabbageMint { .map(|(i, _)| i) .collect::>(); if force_canonical { - inner_key_order.sort_by(|i, j| assets[*i].0.get().cmp(assets[*j].0.get())); + inner_key_order + .sort_by(|i, j| assets[*i].0.to_raw_bytes().cmp(assets[*j].0.to_raw_bytes())); } for (j, (asset_name, coin)) in inner_key_order.into_iter().zip(assets.iter()) { diff --git a/specs/conway/assets.cddl b/specs/conway/assets.cddl index 1fcef9bd..a1b86709 100644 --- a/specs/conway/assets.cddl +++ b/specs/conway/assets.cddl @@ -4,7 +4,7 @@ coin = uint ; but possibly it could be its own type with bounds checking (!=0) positive_coin = coin -asset_name = bytes .size (0..32) +asset_name = bytes .size (0..32) ; @doc Use TryFrom<&str> / TryInto<&str> for utf8 text conversion and RawBytesEncoding for direct bytes access ; these two are technically hand-written but we keep them here so that other code can ; continue thinking they're maps and handle them like so (encoding details, etc)