From fefbe90ea2a9bd7a2c64cf6018cdedc1fdf92eac Mon Sep 17 00:00:00 2001 From: alessandrokonrad Date: Mon, 13 Dec 2021 13:45:53 +0100 Subject: [PATCH 1/4] added to_hex and from_hex --- rust/src/address.rs | 10 +++++++++ rust/src/crypto.rs | 54 +++++++++++++++++++++++++++++++++++++++++++++ rust/src/utils.rs | 44 ++++++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+) diff --git a/rust/src/address.rs b/rust/src/address.rs index 430930fd..760873e6 100644 --- a/rust/src/address.rs +++ b/rust/src/address.rs @@ -276,6 +276,16 @@ from_bytes!(Address, data, { // other CBOR types #[wasm_bindgen] impl Address { + + pub fn to_hex(&self) -> String { + hex::encode(self.to_bytes()) + } + + pub fn from_hex(hex_str : &str) -> Result { + let data: Vec = hex::decode(hex_str).unwrap(); + Ok(Self::from_bytes_impl(data.as_ref())?) + } + pub fn to_bytes(&self) -> Vec { let mut buf = Vec::new(); match &self.0 { diff --git a/rust/src/crypto.rs b/rust/src/crypto.rs index 93144db3..08de9a70 100644 --- a/rust/src/crypto.rs +++ b/rust/src/crypto.rs @@ -129,6 +129,15 @@ impl Bip32PrivateKey { const XPRV_SIZE: usize = 96; self.0.as_ref()[ED25519_PRIVATE_KEY_LENGTH..XPRV_SIZE].to_vec() } + + pub fn to_hex(&self) -> String { + hex::encode(self.as_bytes()) + } + + pub fn from_hex(hex_str : &str) -> Result { + let data: Vec = hex::decode(hex_str).unwrap(); + Ok(Self::from_bytes(data.as_ref())?) + } } #[wasm_bindgen] @@ -195,6 +204,15 @@ impl Bip32PublicKey { const XPUB_SIZE: usize = 64; self.0.as_ref()[ED25519_PUBLIC_KEY_LENGTH..XPUB_SIZE].to_vec() } + + pub fn to_hex(&self) -> String { + hex::encode(self.as_bytes()) + } + + pub fn from_hex(hex_str : &str) -> Result { + let data: Vec = hex::decode(hex_str).unwrap(); + Ok(Self::from_bytes(data.as_ref())?) + } } @@ -279,6 +297,23 @@ impl PrivateKey { pub fn sign(&self, message: &[u8]) -> Ed25519Signature { Ed25519Signature(self.0.sign(&message.to_vec())) } + + pub fn to_hex(&self) -> String { + hex::encode(self.as_bytes()) + } + + pub fn from_hex(hex_str: &str) -> Result { + let data: Vec = hex::decode(hex_str).unwrap(); + let data_slice : &[u8] = data.as_slice(); + crypto::SecretKey::from_binary(data_slice) + .map(key::EitherEd25519SecretKey::Normal) + .or_else(|_| { + crypto::SecretKey::from_binary(data_slice) + .map(key::EitherEd25519SecretKey::Extended) + }) + .map(PrivateKey) + .map_err(|_| JsError::from_str("Invalid secret key")) + } } /// ED25519 key used as public key @@ -326,6 +361,15 @@ impl PublicKey { pub fn hash(&self) -> Ed25519KeyHash { Ed25519KeyHash::from(blake2b224(self.as_bytes().as_ref())) } + + pub fn to_hex(&self) -> String { + hex::encode(self.as_bytes()) + } + + pub fn from_hex(hex_str : &str) -> Result { + let data: Vec = hex::decode(hex_str).unwrap(); + Ok(Self::from_bytes(data.as_ref())?) + } } #[wasm_bindgen] @@ -763,6 +807,16 @@ macro_rules! impl_hash_type { let data: Vec = bech32::FromBase32::from_base32(&u5data).unwrap(); Ok(Self::from_bytes(data)?) } + + pub fn to_hex(&self) -> Result { + Ok(hex::encode(self.to_bytes())) + } + + pub fn from_hex(hex_str: &str) -> Result<$name, JsError> { + let data: Vec = hex::decode(hex_str).unwrap(); + Ok(Self::from_bytes(data)?) + } + } // hash types are the only types in this library to not expect the entire CBOR structure. diff --git a/rust/src/utils.rs b/rust/src/utils.rs index fd5dc13f..b7257ec2 100644 --- a/rust/src/utils.rs +++ b/rust/src/utils.rs @@ -41,6 +41,34 @@ macro_rules! from_bytes { }; } +#[macro_export] +macro_rules! from_hex { + // Custom from_bytes() code + ($name:ident, $data: ident, $body:block) => { + // wasm-exposed JsError return - JsError panics when used outside wasm + #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] + #[wasm_bindgen] + impl $name { + pub fn from_hex($data: &str) -> Result<$name, JsError> { + Ok($body?) + } + } + // non-wasm exposed DeserializeError return + #[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))] + impl $name { + pub fn from_hex($data: &str) -> Result<$name, DeserializeError> $body + } + }; + // Uses Deserialize trait to auto-generate one + ($name:ident) => { + from_hex!($name, hex_str, { + let mut raw = Deserializer::from(std::io::Cursor::new(hex::decode(hex_str).unwrap())); + Self::deserialize(&mut raw) + }); + }; +} + + // There's no need to do wasm vs non-wasm as this call can't fail but // this is here just to provide a default Serialize-based impl // Note: Once again you can't use macros in impls with wasm-bindgen @@ -59,11 +87,27 @@ macro_rules! to_bytes { } } +#[macro_export] +macro_rules! to_hex { + ($name:ident) => { + #[wasm_bindgen] + impl $name { + pub fn to_hex(&self) -> String { + let mut buf = Serializer::new_vec(); + self.serialize(&mut buf).unwrap(); + hex::encode(buf.finalize()) + } + } + } +} + #[macro_export] macro_rules! to_from_bytes { ($name:ident) => { to_bytes!($name); from_bytes!($name); + to_hex!($name); + from_hex!($name); } } From 1f40d1e95ee70987a7ac980c54951097dd85fd1e Mon Sep 17 00:00:00 2001 From: alessandrokonrad Date: Mon, 13 Dec 2021 15:31:56 +0100 Subject: [PATCH 2/4] added error handling for hex --- rust/src/address.rs | 6 ++++-- rust/src/crypto.rs | 29 ++++++++++++++++++++--------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/rust/src/address.rs b/rust/src/address.rs index 760873e6..6c875586 100644 --- a/rust/src/address.rs +++ b/rust/src/address.rs @@ -282,8 +282,10 @@ impl Address { } pub fn from_hex(hex_str : &str) -> Result { - let data: Vec = hex::decode(hex_str).unwrap(); - Ok(Self::from_bytes_impl(data.as_ref())?) + match hex::decode(hex_str) { + Ok(data) => Ok(Self::from_bytes_impl(data.as_ref())?), + Err(e) => Err(JsError::from_str(&e.to_string())) + } } pub fn to_bytes(&self) -> Vec { diff --git a/rust/src/crypto.rs b/rust/src/crypto.rs index 08de9a70..4d71e76d 100644 --- a/rust/src/crypto.rs +++ b/rust/src/crypto.rs @@ -135,8 +135,10 @@ impl Bip32PrivateKey { } pub fn from_hex(hex_str : &str) -> Result { - let data: Vec = hex::decode(hex_str).unwrap(); - Ok(Self::from_bytes(data.as_ref())?) + match hex::decode(hex_str) { + Ok(data) => Ok(Self::from_bytes(data.as_ref())?), + Err(e) => Err(JsError::from_str(&e.to_string())) + } } } @@ -210,8 +212,10 @@ impl Bip32PublicKey { } pub fn from_hex(hex_str : &str) -> Result { - let data: Vec = hex::decode(hex_str).unwrap(); - Ok(Self::from_bytes(data.as_ref())?) + match hex::decode(hex_str) { + Ok(data) => Ok(Self::from_bytes(data.as_ref())?), + Err(e) => Err(JsError::from_str(&e.to_string())) + } } } @@ -303,7 +307,10 @@ impl PrivateKey { } pub fn from_hex(hex_str: &str) -> Result { - let data: Vec = hex::decode(hex_str).unwrap(); + let data : Vec = match hex::decode(hex_str) { + Ok(d) => d, + Err(e) => return Err(JsError::from_str(&e.to_string())) + }; let data_slice : &[u8] = data.as_slice(); crypto::SecretKey::from_binary(data_slice) .map(key::EitherEd25519SecretKey::Normal) @@ -367,8 +374,10 @@ impl PublicKey { } pub fn from_hex(hex_str : &str) -> Result { - let data: Vec = hex::decode(hex_str).unwrap(); - Ok(Self::from_bytes(data.as_ref())?) + match hex::decode(hex_str) { + Ok(data) => Ok(Self::from_bytes(data.as_ref())?), + Err(e) => Err(JsError::from_str(&e.to_string())) + } } } @@ -813,8 +822,10 @@ macro_rules! impl_hash_type { } pub fn from_hex(hex_str: &str) -> Result<$name, JsError> { - let data: Vec = hex::decode(hex_str).unwrap(); - Ok(Self::from_bytes(data)?) + match hex::decode(hex_str) { + Ok(data) => Ok(Self::from_bytes(data)?), + Err(e) => Err(JsError::from_str(&e.to_string())) + } } } From a0c8dacc0d1fdb7362d87220e62a2b0229c0b859 Mon Sep 17 00:00:00 2001 From: alessandrokonrad Date: Mon, 13 Dec 2021 16:05:08 +0100 Subject: [PATCH 3/4] added error handling to macro --- rust/src/utils.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rust/src/utils.rs b/rust/src/utils.rs index b7257ec2..40b4674e 100644 --- a/rust/src/utils.rs +++ b/rust/src/utils.rs @@ -50,7 +50,11 @@ macro_rules! from_hex { #[wasm_bindgen] impl $name { pub fn from_hex($data: &str) -> Result<$name, JsError> { - Ok($body?) + match hex::decode($data) { + Ok(_) => Ok($body?), + Err(e) => Err(JsError::from_str(&e.to_string())) + } + } } // non-wasm exposed DeserializeError return From 004aa4f2732ca223b87f854330bc3093fac8d69f Mon Sep 17 00:00:00 2001 From: vantuz-subhuman Date: Fri, 29 Jul 2022 22:18:16 +0300 Subject: [PATCH 4/4] flowgen update --- rust/pkg/cardano_serialization_lib.js.flow | 1209 ++++++++++++++++++-- rust/src/serialization_macros.rs | 48 + rust/src/utils.rs | 55 - 3 files changed, 1186 insertions(+), 126 deletions(-) diff --git a/rust/pkg/cardano_serialization_lib.js.flow b/rust/pkg/cardano_serialization_lib.js.flow index aa1fa015..69abca9c 100644 --- a/rust/pkg/cardano_serialization_lib.js.flow +++ b/rust/pkg/cardano_serialization_lib.js.flow @@ -5,26 +5,6 @@ * @flow */ -/** - * @param {string} json - * @param {number} schema - * @returns {PlutusData} - */ -declare export function encode_json_str_to_plutus_datum( - json: string, - schema: number -): PlutusData; - -/** - * @param {PlutusData} datum - * @param {number} schema - * @returns {string} - */ -declare export function decode_plutus_datum_to_json_str( - datum: PlutusData, - schema: number -): string; - /** * @param {Transaction} tx * @param {LinearFee} linear_fee @@ -250,6 +230,26 @@ declare export function decode_metadatum_to_json_str( schema: number ): string; +/** + * @param {string} json + * @param {number} schema + * @returns {PlutusData} + */ +declare export function encode_json_str_to_plutus_datum( + json: string, + schema: number +): PlutusData; + +/** + * @param {PlutusData} datum + * @param {number} schema + * @returns {string} + */ +declare export function decode_plutus_datum_to_json_str( + datum: PlutusData, + schema: number +): string; + /** */ @@ -321,52 +321,6 @@ declare export var NetworkIdKind: {| +Mainnet: 1, // 1 |}; -/** - */ - -declare export var LanguageKind: {| - +PlutusV1: 0, // 0 - +PlutusV2: 1, // 1 -|}; - -/** - */ - -declare export var PlutusDataKind: {| - +ConstrPlutusData: 0, // 0 - +Map: 1, // 1 - +List: 2, // 2 - +Integer: 3, // 3 - +Bytes: 4, // 4 -|}; - -/** - */ - -declare export var RedeemerTagKind: {| - +Spend: 0, // 0 - +Mint: 1, // 1 - +Cert: 2, // 2 - +Reward: 3, // 3 -|}; - -/** - * JSON <-> PlutusData conversion schemas. - * Follows ScriptDataJsonSchema in cardano-cli defined at: - * https://github.com/input-output-hk/cardano-node/blob/master/cardano-api/src/Cardano/Api/ScriptData.hs#L254 - * - * All methods here have the following restrictions due to limitations on dependencies: - * * JSON numbers above u64::MAX (positive) or below i64::MIN (negative) will throw errors - * * Hex strings for bytes don't accept odd-length (half-byte) strings. - * cardano-cli seems to support these however but it seems to be different than just 0-padding - * on either side when tested so proceed with caution - */ - -declare export var PlutusDatumSchema: {| - +BasicConversions: 0, // 0 - +DetailedSchema: 1, // 1 -|}; - /** */ @@ -414,6 +368,52 @@ declare export var MetadataJsonSchema: {| +DetailedSchema: 2, // 2 |}; +/** + */ + +declare export var LanguageKind: {| + +PlutusV1: 0, // 0 + +PlutusV2: 1, // 1 +|}; + +/** + */ + +declare export var PlutusDataKind: {| + +ConstrPlutusData: 0, // 0 + +Map: 1, // 1 + +List: 2, // 2 + +Integer: 3, // 3 + +Bytes: 4, // 4 +|}; + +/** + */ + +declare export var RedeemerTagKind: {| + +Spend: 0, // 0 + +Mint: 1, // 1 + +Cert: 2, // 2 + +Reward: 3, // 3 +|}; + +/** + * JSON <-> PlutusData conversion schemas. + * Follows ScriptDataJsonSchema in cardano-cli defined at: + * https://github.com/input-output-hk/cardano-node/blob/master/cardano-api/src/Cardano/Api/ScriptData.hs#L254 + * + * All methods here have the following restrictions due to limitations on dependencies: + * * JSON numbers above u64::MAX (positive) or below i64::MIN (negative) will throw errors + * * Hex strings for bytes don't accept odd-length (half-byte) strings. + * cardano-cli seems to support these however but it seems to be different than just 0-padding + * on either side when tested so proceed with caution + */ + +declare export var PlutusDatumSchema: {| + +BasicConversions: 0, // 0 + +DetailedSchema: 1, // 1 +|}; + /** */ declare export class Address { @@ -441,6 +441,17 @@ declare export class Address { */ static from_json(json: string): Address; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {Address} + */ + static from_hex(hex_str: string): Address; + /** * @returns {Uint8Array} */ @@ -479,6 +490,17 @@ declare export class AssetName { */ static from_bytes(bytes: Uint8Array): AssetName; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {AssetName} + */ + static from_hex(hex_str: string): AssetName; + /** * @returns {string} */ @@ -522,6 +544,17 @@ declare export class AssetNames { */ static from_bytes(bytes: Uint8Array): AssetNames; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {AssetNames} + */ + static from_hex(hex_str: string): AssetNames; + /** * @returns {string} */ @@ -575,6 +608,17 @@ declare export class Assets { */ static from_bytes(bytes: Uint8Array): Assets; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {Assets} + */ + static from_hex(hex_str: string): Assets; + /** * @returns {string} */ @@ -635,6 +679,17 @@ declare export class AuxiliaryData { */ static from_bytes(bytes: Uint8Array): AuxiliaryData; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {AuxiliaryData} + */ + static from_hex(hex_str: string): AuxiliaryData; + /** * @returns {string} */ @@ -812,6 +867,17 @@ declare export class BigInt { */ static from_bytes(bytes: Uint8Array): BigInt; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {BigInt} + */ + static from_hex(hex_str: string): BigInt; + /** * @returns {boolean} */ @@ -882,6 +948,17 @@ declare export class BigNum { */ static from_bytes(bytes: Uint8Array): BigNum; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {BigNum} + */ + static from_hex(hex_str: string): BigNum; + /** * @param {string} string * @returns {BigNum} @@ -1051,6 +1128,17 @@ declare export class Bip32PrivateKey { * @returns {Uint8Array} */ chaincode(): Uint8Array; + + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {Bip32PrivateKey} + */ + static from_hex(hex_str: string): Bip32PrivateKey; } /** */ @@ -1117,6 +1205,17 @@ declare export class Bip32PublicKey { * @returns {Uint8Array} */ chaincode(): Uint8Array; + + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {Bip32PublicKey} + */ + static from_hex(hex_str: string): Bip32PublicKey; } /** */ @@ -1134,6 +1233,17 @@ declare export class Block { */ static from_bytes(bytes: Uint8Array): Block; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {Block} + */ + static from_hex(hex_str: string): Block; + /** * @returns {string} */ @@ -1246,6 +1356,17 @@ declare export class BootstrapWitness { */ static from_bytes(bytes: Uint8Array): BootstrapWitness; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {BootstrapWitness} + */ + static from_hex(hex_str: string): BootstrapWitness; + /** * @returns {string} */ @@ -1409,6 +1530,17 @@ declare export class Certificate { */ static from_bytes(bytes: Uint8Array): Certificate; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {Certificate} + */ + static from_hex(hex_str: string): Certificate; + /** * @returns {string} */ @@ -1533,6 +1665,17 @@ declare export class Certificates { */ static from_bytes(bytes: Uint8Array): Certificates; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {Certificates} + */ + static from_hex(hex_str: string): Certificates; + /** * @returns {string} */ @@ -1586,6 +1729,17 @@ declare export class ConstrPlutusData { */ static from_bytes(bytes: Uint8Array): ConstrPlutusData; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {ConstrPlutusData} + */ + static from_hex(hex_str: string): ConstrPlutusData; + /** * @returns {BigNum} */ @@ -1619,6 +1773,17 @@ declare export class CostModel { */ static from_bytes(bytes: Uint8Array): CostModel; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {CostModel} + */ + static from_hex(hex_str: string): CostModel; + /** * Creates a new CostModels instance of an unrestricted length * @returns {CostModel} @@ -1662,6 +1827,17 @@ declare export class Costmdls { */ static from_bytes(bytes: Uint8Array): Costmdls; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {Costmdls} + */ + static from_hex(hex_str: string): Costmdls; + /** * @returns {Costmdls} */ @@ -1706,6 +1882,17 @@ declare export class DNSRecordAorAAAA { */ static from_bytes(bytes: Uint8Array): DNSRecordAorAAAA; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {DNSRecordAorAAAA} + */ + static from_hex(hex_str: string): DNSRecordAorAAAA; + /** * @param {string} dns_name * @returns {DNSRecordAorAAAA} @@ -1733,6 +1920,17 @@ declare export class DNSRecordSRV { */ static from_bytes(bytes: Uint8Array): DNSRecordSRV; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {DNSRecordSRV} + */ + static from_hex(hex_str: string): DNSRecordSRV; + /** * @param {string} dns_name * @returns {DNSRecordSRV} @@ -1862,6 +2060,17 @@ declare export class Ed25519KeyHashes { */ static from_bytes(bytes: Uint8Array): Ed25519KeyHashes; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {Ed25519KeyHashes} + */ + static from_hex(hex_str: string): Ed25519KeyHashes; + /** * @returns {string} */ @@ -1986,6 +2195,17 @@ declare export class ExUnitPrices { */ static from_bytes(bytes: Uint8Array): ExUnitPrices; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {ExUnitPrices} + */ + static from_hex(hex_str: string): ExUnitPrices; + /** * @returns {UnitInterval} */ @@ -2019,6 +2239,17 @@ declare export class ExUnits { */ static from_bytes(bytes: Uint8Array): ExUnits; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {ExUnits} + */ + static from_hex(hex_str: string): ExUnits; + /** * @returns {BigNum} */ @@ -2052,6 +2283,17 @@ declare export class GeneralTransactionMetadata { */ static from_bytes(bytes: Uint8Array): GeneralTransactionMetadata; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {GeneralTransactionMetadata} + */ + static from_hex(hex_str: string): GeneralTransactionMetadata; + /** * @returns {string} */ @@ -2190,6 +2432,17 @@ declare export class GenesisHashes { */ static from_bytes(bytes: Uint8Array): GenesisHashes; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {GenesisHashes} + */ + static from_hex(hex_str: string): GenesisHashes; + /** * @returns {string} */ @@ -2243,6 +2496,17 @@ declare export class GenesisKeyDelegation { */ static from_bytes(bytes: Uint8Array): GenesisKeyDelegation; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {GenesisKeyDelegation} + */ + static from_hex(hex_str: string): GenesisKeyDelegation; + /** * @returns {string} */ @@ -2302,6 +2566,17 @@ declare export class Header { */ static from_bytes(bytes: Uint8Array): Header; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {Header} + */ + static from_hex(hex_str: string): Header; + /** * @returns {string} */ @@ -2351,6 +2626,17 @@ declare export class HeaderBody { */ static from_bytes(bytes: Uint8Array): HeaderBody; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {HeaderBody} + */ + static from_hex(hex_str: string): HeaderBody; + /** * @returns {string} */ @@ -2524,6 +2810,17 @@ declare export class Int { */ static from_bytes(bytes: Uint8Array): Int; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {Int} + */ + static from_hex(hex_str: string): Int; + /** * @param {BigNum} x * @returns {Int} @@ -2620,6 +2917,17 @@ declare export class Ipv4 { */ static from_bytes(bytes: Uint8Array): Ipv4; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {Ipv4} + */ + static from_hex(hex_str: string): Ipv4; + /** * @returns {string} */ @@ -2663,6 +2971,17 @@ declare export class Ipv6 { */ static from_bytes(bytes: Uint8Array): Ipv6; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {Ipv6} + */ + static from_hex(hex_str: string): Ipv6; + /** * @returns {string} */ @@ -2761,6 +3080,17 @@ declare export class Language { */ static from_bytes(bytes: Uint8Array): Language; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {Language} + */ + static from_hex(hex_str: string): Language; + /** * @returns {Language} */ @@ -2861,6 +3191,17 @@ declare export class MIRToStakeCredentials { */ static from_bytes(bytes: Uint8Array): MIRToStakeCredentials; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {MIRToStakeCredentials} + */ + static from_hex(hex_str: string): MIRToStakeCredentials; + /** * @returns {string} */ @@ -2921,6 +3262,17 @@ declare export class MetadataList { */ static from_bytes(bytes: Uint8Array): MetadataList; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {MetadataList} + */ + static from_hex(hex_str: string): MetadataList; + /** * @returns {MetadataList} */ @@ -2958,6 +3310,17 @@ declare export class MetadataMap { */ static from_bytes(bytes: Uint8Array): MetadataMap; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {MetadataMap} + */ + static from_hex(hex_str: string): MetadataMap; + /** * @returns {MetadataMap} */ @@ -3043,6 +3406,17 @@ declare export class Mint { */ static from_bytes(bytes: Uint8Array): Mint; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {Mint} + */ + static from_hex(hex_str: string): Mint; + /** * @returns {string} */ @@ -3162,6 +3536,17 @@ declare export class MoveInstantaneousReward { */ static from_bytes(bytes: Uint8Array): MoveInstantaneousReward; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {MoveInstantaneousReward} + */ + static from_hex(hex_str: string): MoveInstantaneousReward; + /** * @returns {string} */ @@ -3231,6 +3616,17 @@ declare export class MoveInstantaneousRewardsCert { */ static from_bytes(bytes: Uint8Array): MoveInstantaneousRewardsCert; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {MoveInstantaneousRewardsCert} + */ + static from_hex(hex_str: string): MoveInstantaneousRewardsCert; + /** * @returns {string} */ @@ -3276,6 +3672,17 @@ declare export class MultiAsset { */ static from_bytes(bytes: Uint8Array): MultiAsset; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {MultiAsset} + */ + static from_hex(hex_str: string): MultiAsset; + /** * @returns {string} */ @@ -3371,6 +3778,17 @@ declare export class MultiHostName { */ static from_bytes(bytes: Uint8Array): MultiHostName; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {MultiHostName} + */ + static from_hex(hex_str: string): MultiHostName; + /** * @returns {string} */ @@ -3414,6 +3832,17 @@ declare export class NativeScript { */ static from_bytes(bytes: Uint8Array): NativeScript; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {NativeScript} + */ + static from_hex(hex_str: string): NativeScript; + /** * @returns {string} */ @@ -3556,6 +3985,17 @@ declare export class NetworkId { */ static from_bytes(bytes: Uint8Array): NetworkId; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {NetworkId} + */ + static from_hex(hex_str: string): NetworkId; + /** * @returns {string} */ @@ -3630,10 +4070,21 @@ declare export class Nonce { to_bytes(): Uint8Array; /** - * @param {Uint8Array} bytes + * @param {Uint8Array} bytes + * @returns {Nonce} + */ + static from_bytes(bytes: Uint8Array): Nonce; + + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str * @returns {Nonce} */ - static from_bytes(bytes: Uint8Array): Nonce; + static from_hex(hex_str: string): Nonce; /** * @returns {Nonce} @@ -3667,6 +4118,17 @@ declare export class OperationalCert { */ static from_bytes(bytes: Uint8Array): OperationalCert; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {OperationalCert} + */ + static from_hex(hex_str: string): OperationalCert; + /** * @returns {string} */ @@ -3733,6 +4195,17 @@ declare export class PlutusData { */ static from_bytes(bytes: Uint8Array): PlutusData; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {PlutusData} + */ + static from_hex(hex_str: string): PlutusData; + /** * @param {ConstrPlutusData} constr_plutus_data * @returns {PlutusData} @@ -3818,6 +4291,17 @@ declare export class PlutusList { */ static from_bytes(bytes: Uint8Array): PlutusList; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {PlutusList} + */ + static from_hex(hex_str: string): PlutusList; + /** * @returns {PlutusList} */ @@ -3855,6 +4339,17 @@ declare export class PlutusMap { */ static from_bytes(bytes: Uint8Array): PlutusMap; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {PlutusMap} + */ + static from_hex(hex_str: string): PlutusMap; + /** * @returns {PlutusMap} */ @@ -3899,6 +4394,17 @@ declare export class PlutusScript { */ static from_bytes(bytes: Uint8Array): PlutusScript; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {PlutusScript} + */ + static from_hex(hex_str: string): PlutusScript; + /** * * Creates a new Plutus script from the RAW bytes of the compiled script. * * This does NOT include any CBOR encoding around these bytes (e.g. from "cborBytes" in cardano-cli) @@ -3978,6 +4484,17 @@ declare export class PlutusScripts { */ static from_bytes(bytes: Uint8Array): PlutusScripts; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {PlutusScripts} + */ + static from_hex(hex_str: string): PlutusScripts; + /** * @returns {PlutusScripts} */ @@ -4201,6 +4718,17 @@ declare export class PoolMetadata { */ static from_bytes(bytes: Uint8Array): PoolMetadata; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {PoolMetadata} + */ + static from_hex(hex_str: string): PoolMetadata; + /** * @returns {string} */ @@ -4289,6 +4817,17 @@ declare export class PoolParams { */ static from_bytes(bytes: Uint8Array): PoolParams; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {PoolParams} + */ + static from_hex(hex_str: string): PoolParams; + /** * @returns {string} */ @@ -4390,6 +4929,17 @@ declare export class PoolRegistration { */ static from_bytes(bytes: Uint8Array): PoolRegistration; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {PoolRegistration} + */ + static from_hex(hex_str: string): PoolRegistration; + /** * @returns {string} */ @@ -4433,6 +4983,17 @@ declare export class PoolRetirement { */ static from_bytes(bytes: Uint8Array): PoolRetirement; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {PoolRetirement} + */ + static from_hex(hex_str: string): PoolRetirement; + /** * @returns {string} */ @@ -4527,6 +5088,17 @@ declare export class PrivateKey { * @returns {Ed25519Signature} */ sign(message: Uint8Array): Ed25519Signature; + + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {PrivateKey} + */ + static from_hex(hex_str: string): PrivateKey; } /** */ @@ -4544,6 +5116,17 @@ declare export class ProposedProtocolParameterUpdates { */ static from_bytes(bytes: Uint8Array): ProposedProtocolParameterUpdates; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {ProposedProtocolParameterUpdates} + */ + static from_hex(hex_str: string): ProposedProtocolParameterUpdates; + /** * @returns {string} */ @@ -4607,6 +5190,17 @@ declare export class ProtocolParamUpdate { */ static from_bytes(bytes: Uint8Array): ProtocolParamUpdate; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {ProtocolParamUpdate} + */ + static from_hex(hex_str: string): ProtocolParamUpdate; + /** * @returns {string} */ @@ -4878,6 +5472,17 @@ declare export class ProtocolVersion { */ static from_bytes(bytes: Uint8Array): ProtocolVersion; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {ProtocolVersion} + */ + static from_hex(hex_str: string): ProtocolVersion; + /** * @returns {string} */ @@ -4955,6 +5560,17 @@ declare export class PublicKey { * @returns {Ed25519KeyHash} */ hash(): Ed25519KeyHash; + + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {PublicKey} + */ + static from_hex(hex_str: string): PublicKey; } /** */ @@ -4997,6 +5613,17 @@ declare export class Redeemer { */ static from_bytes(bytes: Uint8Array): Redeemer; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {Redeemer} + */ + static from_hex(hex_str: string): Redeemer; + /** * @returns {RedeemerTag} */ @@ -5047,6 +5674,17 @@ declare export class RedeemerTag { */ static from_bytes(bytes: Uint8Array): RedeemerTag; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {RedeemerTag} + */ + static from_hex(hex_str: string): RedeemerTag; + /** * @returns {RedeemerTag} */ @@ -5088,6 +5726,17 @@ declare export class Redeemers { */ static from_bytes(bytes: Uint8Array): Redeemers; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {Redeemers} + */ + static from_hex(hex_str: string): Redeemers; + /** * @returns {Redeemers} */ @@ -5130,6 +5779,17 @@ declare export class Relay { */ static from_bytes(bytes: Uint8Array): Relay; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {Relay} + */ + static from_hex(hex_str: string): Relay; + /** * @returns {string} */ @@ -5200,6 +5860,17 @@ declare export class Relays { */ static from_bytes(bytes: Uint8Array): Relays; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {Relays} + */ + static from_hex(hex_str: string): Relays; + /** * @returns {string} */ @@ -5281,6 +5952,17 @@ declare export class RewardAddresses { */ static from_bytes(bytes: Uint8Array): RewardAddresses; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {RewardAddresses} + */ + static from_hex(hex_str: string): RewardAddresses; + /** * @returns {string} */ @@ -5334,6 +6016,17 @@ declare export class ScriptAll { */ static from_bytes(bytes: Uint8Array): ScriptAll; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {ScriptAll} + */ + static from_hex(hex_str: string): ScriptAll; + /** * @returns {string} */ @@ -5377,6 +6070,17 @@ declare export class ScriptAny { */ static from_bytes(bytes: Uint8Array): ScriptAny; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {ScriptAny} + */ + static from_hex(hex_str: string): ScriptAny; + /** * @returns {string} */ @@ -5498,6 +6202,17 @@ declare export class ScriptHashes { */ static from_bytes(bytes: Uint8Array): ScriptHashes; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {ScriptHashes} + */ + static from_hex(hex_str: string): ScriptHashes; + /** * @returns {string} */ @@ -5551,6 +6266,17 @@ declare export class ScriptNOfK { */ static from_bytes(bytes: Uint8Array): ScriptNOfK; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {ScriptNOfK} + */ + static from_hex(hex_str: string): ScriptNOfK; + /** * @returns {string} */ @@ -5600,6 +6326,17 @@ declare export class ScriptPubkey { */ static from_bytes(bytes: Uint8Array): ScriptPubkey; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {ScriptPubkey} + */ + static from_hex(hex_str: string): ScriptPubkey; + /** * @returns {string} */ @@ -5643,6 +6380,17 @@ declare export class ScriptRef { */ static from_bytes(bytes: Uint8Array): ScriptRef; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {ScriptRef} + */ + static from_hex(hex_str: string): ScriptRef; + /** * @returns {string} */ @@ -5699,13 +6447,24 @@ declare export class SingleHostAddr { /** * @returns {Uint8Array} */ - to_bytes(): Uint8Array; + to_bytes(): Uint8Array; + + /** + * @param {Uint8Array} bytes + * @returns {SingleHostAddr} + */ + static from_bytes(bytes: Uint8Array): SingleHostAddr; + + /** + * @returns {string} + */ + to_hex(): string; /** - * @param {Uint8Array} bytes + * @param {string} hex_str * @returns {SingleHostAddr} */ - static from_bytes(bytes: Uint8Array): SingleHostAddr; + static from_hex(hex_str: string): SingleHostAddr; /** * @returns {string} @@ -5762,6 +6521,17 @@ declare export class SingleHostName { */ static from_bytes(bytes: Uint8Array): SingleHostName; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {SingleHostName} + */ + static from_hex(hex_str: string): SingleHostName; + /** * @returns {string} */ @@ -5838,6 +6608,17 @@ declare export class StakeCredential { */ static from_bytes(bytes: Uint8Array): StakeCredential; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {StakeCredential} + */ + static from_hex(hex_str: string): StakeCredential; + /** * @returns {string} */ @@ -5870,6 +6651,17 @@ declare export class StakeCredentials { */ static from_bytes(bytes: Uint8Array): StakeCredentials; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {StakeCredentials} + */ + static from_hex(hex_str: string): StakeCredentials; + /** * @returns {string} */ @@ -5923,6 +6715,17 @@ declare export class StakeDelegation { */ static from_bytes(bytes: Uint8Array): StakeDelegation; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {StakeDelegation} + */ + static from_hex(hex_str: string): StakeDelegation; + /** * @returns {string} */ @@ -5975,6 +6778,17 @@ declare export class StakeDeregistration { */ static from_bytes(bytes: Uint8Array): StakeDeregistration; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {StakeDeregistration} + */ + static from_hex(hex_str: string): StakeDeregistration; + /** * @returns {string} */ @@ -6018,6 +6832,17 @@ declare export class StakeRegistration { */ static from_bytes(bytes: Uint8Array): StakeRegistration; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {StakeRegistration} + */ + static from_hex(hex_str: string): StakeRegistration; + /** * @returns {string} */ @@ -6087,6 +6912,17 @@ declare export class TimelockExpiry { */ static from_bytes(bytes: Uint8Array): TimelockExpiry; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {TimelockExpiry} + */ + static from_hex(hex_str: string): TimelockExpiry; + /** * @returns {string} */ @@ -6144,6 +6980,17 @@ declare export class TimelockStart { */ static from_bytes(bytes: Uint8Array): TimelockStart; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {TimelockStart} + */ + static from_hex(hex_str: string): TimelockStart; + /** * @returns {string} */ @@ -6205,6 +7052,17 @@ declare export class Transaction { */ static from_bytes(bytes: Uint8Array): Transaction; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {Transaction} + */ + static from_hex(hex_str: string): Transaction; + /** * @returns {string} */ @@ -6274,6 +7132,17 @@ declare export class TransactionBodies { */ static from_bytes(bytes: Uint8Array): TransactionBodies; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {TransactionBodies} + */ + static from_hex(hex_str: string): TransactionBodies; + /** * @returns {string} */ @@ -6327,6 +7196,17 @@ declare export class TransactionBody { */ static from_bytes(bytes: Uint8Array): TransactionBody; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {TransactionBody} + */ + static from_hex(hex_str: string): TransactionBody; + /** * @returns {string} */ @@ -7211,6 +8091,17 @@ declare export class TransactionInput { */ static from_bytes(bytes: Uint8Array): TransactionInput; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {TransactionInput} + */ + static from_hex(hex_str: string): TransactionInput; + /** * @returns {string} */ @@ -7260,6 +8151,17 @@ declare export class TransactionInputs { */ static from_bytes(bytes: Uint8Array): TransactionInputs; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {TransactionInputs} + */ + static from_hex(hex_str: string): TransactionInputs; + /** * @returns {string} */ @@ -7318,6 +8220,17 @@ declare export class TransactionMetadatum { */ static from_bytes(bytes: Uint8Array): TransactionMetadatum; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {TransactionMetadatum} + */ + static from_hex(hex_str: string): TransactionMetadatum; + /** * @param {MetadataMap} map * @returns {TransactionMetadatum} @@ -7394,6 +8307,17 @@ declare export class TransactionMetadatumLabels { */ static from_bytes(bytes: Uint8Array): TransactionMetadatumLabels; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {TransactionMetadatumLabels} + */ + static from_hex(hex_str: string): TransactionMetadatumLabels; + /** * @returns {TransactionMetadatumLabels} */ @@ -7431,6 +8355,17 @@ declare export class TransactionOutput { */ static from_bytes(bytes: Uint8Array): TransactionOutput; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {TransactionOutput} + */ + static from_hex(hex_str: string): TransactionOutput; + /** * @returns {string} */ @@ -7623,6 +8558,17 @@ declare export class TransactionOutputs { */ static from_bytes(bytes: Uint8Array): TransactionOutputs; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {TransactionOutputs} + */ + static from_hex(hex_str: string): TransactionOutputs; + /** * @returns {string} */ @@ -7676,6 +8622,17 @@ declare export class TransactionUnspentOutput { */ static from_bytes(bytes: Uint8Array): TransactionUnspentOutput; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {TransactionUnspentOutput} + */ + static from_hex(hex_str: string): TransactionUnspentOutput; + /** * @param {TransactionInput} input * @param {TransactionOutput} output @@ -7738,6 +8695,17 @@ declare export class TransactionWitnessSet { */ static from_bytes(bytes: Uint8Array): TransactionWitnessSet; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {TransactionWitnessSet} + */ + static from_hex(hex_str: string): TransactionWitnessSet; + /** * @returns {string} */ @@ -7835,6 +8803,17 @@ declare export class TransactionWitnessSets { */ static from_bytes(bytes: Uint8Array): TransactionWitnessSets; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {TransactionWitnessSets} + */ + static from_hex(hex_str: string): TransactionWitnessSets; + /** * @returns {string} */ @@ -8065,6 +9044,17 @@ declare export class URL { */ static from_bytes(bytes: Uint8Array): URL; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {URL} + */ + static from_hex(hex_str: string): URL; + /** * @param {string} url * @returns {URL} @@ -8092,6 +9082,17 @@ declare export class UnitInterval { */ static from_bytes(bytes: Uint8Array): UnitInterval; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {UnitInterval} + */ + static from_hex(hex_str: string): UnitInterval; + /** * @returns {string} */ @@ -8141,6 +9142,17 @@ declare export class Update { */ static from_bytes(bytes: Uint8Array): Update; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {Update} + */ + static from_hex(hex_str: string): Update; + /** * @returns {string} */ @@ -8193,6 +9205,17 @@ declare export class VRFCert { */ static from_bytes(bytes: Uint8Array): VRFCert; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {VRFCert} + */ + static from_hex(hex_str: string): VRFCert; + /** * @returns {string} */ @@ -8320,6 +9343,17 @@ declare export class Value { */ static from_bytes(bytes: Uint8Array): Value; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {Value} + */ + static from_hex(hex_str: string): Value; + /** * @returns {string} */ @@ -8426,6 +9460,17 @@ declare export class Vkey { */ static from_bytes(bytes: Uint8Array): Vkey; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {Vkey} + */ + static from_hex(hex_str: string): Vkey; + /** * @param {PublicKey} pk * @returns {Vkey} @@ -8479,6 +9524,17 @@ declare export class Vkeywitness { */ static from_bytes(bytes: Uint8Array): Vkeywitness; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {Vkeywitness} + */ + static from_hex(hex_str: string): Vkeywitness; + /** * @returns {string} */ @@ -8554,6 +9610,17 @@ declare export class Withdrawals { */ static from_bytes(bytes: Uint8Array): Withdrawals; + /** + * @returns {string} + */ + to_hex(): string; + + /** + * @param {string} hex_str + * @returns {Withdrawals} + */ + static from_hex(hex_str: string): Withdrawals; + /** * @returns {string} */ diff --git a/rust/src/serialization_macros.rs b/rust/src/serialization_macros.rs index 80a99d96..7cba0577 100644 --- a/rust/src/serialization_macros.rs +++ b/rust/src/serialization_macros.rs @@ -49,10 +49,58 @@ macro_rules! to_bytes { } } + +#[macro_export] +macro_rules! from_hex { + // Custom from_bytes() code + ($name:ident, $data: ident, $body:block) => { + // wasm-exposed JsError return - JsError panics when used outside wasm + #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] + #[wasm_bindgen] + impl $name { + pub fn from_hex($data: &str) -> Result<$name, JsError> { + match hex::decode($data) { + Ok(_) => Ok($body?), + Err(e) => Err(JsError::from_str(&e.to_string())) + } + + } + } + // non-wasm exposed DeserializeError return + #[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))] + impl $name { + pub fn from_hex($data: &str) -> Result<$name, DeserializeError> $body + } + }; + // Uses Deserialize trait to auto-generate one + ($name:ident) => { + from_hex!($name, hex_str, { + let mut raw = Deserializer::from(std::io::Cursor::new(hex::decode(hex_str).unwrap())); + Self::deserialize(&mut raw) + }); + }; +} + +#[macro_export] +macro_rules! to_hex { + ($name:ident) => { + #[wasm_bindgen] + impl $name { + pub fn to_hex(&self) -> String { + let mut buf = Serializer::new_vec(); + self.serialize(&mut buf).unwrap(); + hex::encode(buf.finalize()) + } + } + } +} + #[macro_export] macro_rules! to_from_bytes { ($name:ident) => { to_bytes!($name); from_bytes!($name); + to_hex!($name); + from_hex!($name); } } \ No newline at end of file diff --git a/rust/src/utils.rs b/rust/src/utils.rs index e95a7138..a336ef8c 100644 --- a/rust/src/utils.rs +++ b/rust/src/utils.rs @@ -46,61 +46,6 @@ macro_rules! to_from_json { } } -#[macro_export] -macro_rules! from_hex { - // Custom from_bytes() code - ($name:ident, $data: ident, $body:block) => { - // wasm-exposed JsError return - JsError panics when used outside wasm - #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] - #[wasm_bindgen] - impl $name { - pub fn from_hex($data: &str) -> Result<$name, JsError> { - match hex::decode($data) { - Ok(_) => Ok($body?), - Err(e) => Err(JsError::from_str(&e.to_string())) - } - - } - } - // non-wasm exposed DeserializeError return - #[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))] - impl $name { - pub fn from_hex($data: &str) -> Result<$name, DeserializeError> $body - } - }; - // Uses Deserialize trait to auto-generate one - ($name:ident) => { - from_hex!($name, hex_str, { - let mut raw = Deserializer::from(std::io::Cursor::new(hex::decode(hex_str).unwrap())); - Self::deserialize(&mut raw) - }); - }; -} - -#[macro_export] -macro_rules! to_hex { - ($name:ident) => { - #[wasm_bindgen] - impl $name { - pub fn to_hex(&self) -> String { - let mut buf = Serializer::new_vec(); - self.serialize(&mut buf).unwrap(); - hex::encode(buf.finalize()) - } - } - } -} - -#[macro_export] -macro_rules! to_from_bytes { - ($name:ident) => { - to_bytes!($name); - from_bytes!($name); - to_hex!($name); - from_hex!($name); - } -} - #[wasm_bindgen] #[derive(Clone, Debug)] pub struct TransactionUnspentOutput {