@@ -735,9 +735,9 @@ def serialize(self, value: Union[list, bytes]) -> Union[list, str]:
735735 else :
736736 return f'0x{ value .hex ()} '
737737
738- def deserialize (self , value : Union [list , str , bytes ]) -> Union [list , bytes ]:
738+ def deserialize (self , value : Union [list , str , bytes , bytearray ]) -> Union [list , bytes ]:
739739
740- if type (value ) not in [list , str , bytes ]:
740+ if type (value ) not in [list , str , bytes , bytearray ]:
741741 raise ScaleDeserializeException ('value should be of type list, str or bytes' )
742742
743743 if type (value ) is str :
@@ -749,6 +749,9 @@ def deserialize(self, value: Union[list, str, bytes]) -> Union[list, bytes]:
749749 if len (value ) != self .length :
750750 raise ScaleDeserializeException ('Length of array does not match size of value' )
751751
752+ if type (value ) is bytearray :
753+ value = bytes (value )
754+
752755 if type (value ) is bytes :
753756 if self .type_def is not U8 :
754757 raise ScaleDeserializeException ('Only an Array of U8 can be represented as (hex)bytes' )
@@ -950,10 +953,13 @@ def _encode(self, value: Union[str, bytes]) -> ScaleBytes:
950953 def serialize (self , value : bytes ) -> str :
951954 return f'0x{ value .hex ()} '
952955
953- def deserialize (self , value : Union [str , bytes ]) -> bytes :
956+ def deserialize (self , value : Union [str , bytes , bytearray ]) -> bytes :
954957 if type (value ) is str :
955958 value = bytes .fromhex (value [2 :])
956959
960+ if type (value ) is bytearray :
961+ value = bytes (value )
962+
957963 if type (value ) is not bytes :
958964 raise ScaleDeserializeException ('value should be of type str or bytes' )
959965
0 commit comments