diff --git a/bindings/nodejs/lib/types/block/address.ts b/bindings/nodejs/lib/types/block/address.ts index ec428452e4..c253dbc033 100644 --- a/bindings/nodejs/lib/types/block/address.ts +++ b/bindings/nodejs/lib/types/block/address.ts @@ -139,7 +139,7 @@ class NftAddress extends Address { } /** - * An implicit account creation address. + * An implicit account creation address that can be used to convert a Basic Output to an Account Output. */ class ImplicitAccountCreationAddress extends Address { private pubKeyHash: HexEncodedString; diff --git a/bindings/python/iota_sdk/types/address.py b/bindings/python/iota_sdk/types/address.py index 1884bf4b40..3b52c8e530 100644 --- a/bindings/python/iota_sdk/types/address.py +++ b/bindings/python/iota_sdk/types/address.py @@ -14,10 +14,14 @@ class AddressType(IntEnum): ED25519 (0): Ed25519 address. ACCOUNT (8): Account address. NFT (16): Nft address. + IMPLICIT_ACCOUNT_CREATION (24): Implicit Account Creation address. + RESTRICTED (40): Address with restricted capabilities. """ ED25519 = 0 ACCOUNT = 8 NFT = 16 + IMPLICIT_ACCOUNT_CREATION = 24 + RESTRICTED = 40 @json @@ -59,6 +63,56 @@ class NFTAddress: type: int = field(default_factory=lambda: int(AddressType.NFT), init=False) +@json +@dataclass +class ImplicitAccountCreationAddress: + """An implicit account creation address that can be used to convert a Basic Output to an Account Output. + Attributes: + address: The hex encoded Ed25519 Address. + """ + address: Ed25519Address + type: int = field(default_factory=lambda: int( + AddressType.IMPLICIT_ACCOUNT_CREATION), init=False) + + @staticmethod + def _to_dict_custom(addr_dict: dict) -> dict: + """ + Converts an implicit account creation address to the dictionary representation. + """ + if 'address' in addr_dict: + address = addr_dict.pop('address') + addr_dict['pubKeyHash'] = address.pop('pubKeyHash') + return addr_dict + + @staticmethod + def from_dict(addr_dict: dict): + """ + Creates an implicit account creation address from a dictionary representation. + """ + return ImplicitAccountCreationAddress(Ed25519Address(addr_dict['pubKeyHash'])) + + +@json +@dataclass +class RestrictedAddress: + """Represents an address with restricted capabilities. + Attributes: + address: The inner restricted Address. + allowed_capabilities: The allowed capabilities bitflags. + """ + address: Union[Ed25519Address, AccountAddress, NFTAddress] + allowed_capabilities: HexStr = field(default='0x00', init=False) + type: int = field(default_factory=lambda: int( + AddressType.RESTRICTED), init=False) + + def with_allowed_capabilities(self, allowed_capabilities: bytes): + """Sets the allowed capabilities from a byte array. + Attributes: + allowed_capabilities: The allowed capabilities bitflags. + """ + self.allowed_capabilities = '0x00' + allowed_capabilities.hex() + + @json @dataclass class AddressWithUnspentOutputs(): @@ -70,7 +124,8 @@ class AddressWithUnspentOutputs(): output_ids: bool -Address: TypeAlias = Union[Ed25519Address, AccountAddress, NFTAddress] +Address: TypeAlias = Union[Ed25519Address, AccountAddress, + NFTAddress, ImplicitAccountCreationAddress, RestrictedAddress] def deserialize_address(d: Dict[str, Any]) -> Address: @@ -87,6 +142,10 @@ def deserialize_address(d: Dict[str, Any]) -> Address: return AccountAddress.from_dict(d) if address_type == AddressType.NFT: return NFTAddress.from_dict(d) + if address_type == AddressType.IMPLICIT_ACCOUNT_CREATION: + return ImplicitAccountCreationAddress.from_dict(d) + if address_type == AddressType.RESTRICTED: + return RestrictedAddress.from_dict(d) raise Exception(f'invalid address type: {address_type}') diff --git a/bindings/python/iota_sdk/types/token_scheme.py b/bindings/python/iota_sdk/types/token_scheme.py index 95d671ce2b..8d63c690ed 100644 --- a/bindings/python/iota_sdk/types/token_scheme.py +++ b/bindings/python/iota_sdk/types/token_scheme.py @@ -23,7 +23,7 @@ class SimpleTokenScheme: type: int = field(default_factory=lambda: 0, init=False) @staticmethod - def to_dict_custom(config): + def _to_dict_custom(config): """ The function converts integer values in the config to hexadecimal strings. """ diff --git a/bindings/python/iota_sdk/utils.py b/bindings/python/iota_sdk/utils.py index 5e232e7fd4..6c27d1e6aa 100644 --- a/bindings/python/iota_sdk/utils.py +++ b/bindings/python/iota_sdk/utils.py @@ -79,7 +79,7 @@ def parse_bech32_address(address: str) -> Address: 'address': address }) - deserialize_address(response) + return deserialize_address(response) @staticmethod def is_address_valid(address: str) -> bool: diff --git a/sdk/src/types/block/address/implicit_account_creation.rs b/sdk/src/types/block/address/implicit_account_creation.rs index 22e76e7787..cbb4344c55 100644 --- a/sdk/src/types/block/address/implicit_account_creation.rs +++ b/sdk/src/types/block/address/implicit_account_creation.rs @@ -6,7 +6,9 @@ use packable::Packable; use crate::types::block::address::Ed25519Address; -/// An implicit account creation address that can be used to transition an account. +/// An implicit account creation address that can be used to convert a +/// [`BasicOutput`](crate::types::block::output::BasicOutput) to an +/// [`AccountOutput`](crate::types::block::output::AccountOutput). #[derive(Copy, Clone, Debug, Display, Eq, PartialEq, Ord, PartialOrd, Hash, FromStr, AsRef, Deref, From, Packable)] #[as_ref(forward)] pub struct ImplicitAccountCreationAddress(Ed25519Address);