diff --git a/async_substrate_interface/async_substrate.py b/async_substrate_interface/async_substrate.py index f60902b..8df2341 100644 --- a/async_substrate_interface/async_substrate.py +++ b/async_substrate_interface/async_substrate.py @@ -21,8 +21,6 @@ ) import asyncstdlib as a -from bittensor_wallet.keypair import Keypair -from bittensor_wallet.utils import SS58_FORMAT from bt_decode import MetadataV15, PortableRegistry, decode as decode_by_type_string from scalecodec.base import ScaleBytes, ScaleType, RuntimeConfigurationObject from scalecodec.types import ( @@ -35,12 +33,14 @@ from websockets.asyncio.client import connect from websockets.exceptions import ConnectionClosed +from async_substrate_interface.const import SS58_FORMAT from async_substrate_interface.errors import ( SubstrateRequestException, ExtrinsicNotFound, BlockNotFound, MaxRetriesExceeded, ) +from async_substrate_interface.protocols import Keypair from async_substrate_interface.types import ( ScaleObj, RequestManager, @@ -2628,6 +2628,8 @@ async def create_signed_extrinsic( # Sign payload signature = keypair.sign(signature_payload) + if inspect.isawaitable(signature): + signature = await signature # Create extrinsic extrinsic = self.runtime_config.create_scale_object( diff --git a/async_substrate_interface/const.py b/async_substrate_interface/const.py new file mode 100644 index 0000000..983f9e4 --- /dev/null +++ b/async_substrate_interface/const.py @@ -0,0 +1,2 @@ +# Re-define SS58 format here to remove unnecessary dependencies. +SS58_FORMAT = 42 diff --git a/async_substrate_interface/protocols.py b/async_substrate_interface/protocols.py new file mode 100644 index 0000000..b50605f --- /dev/null +++ b/async_substrate_interface/protocols.py @@ -0,0 +1,36 @@ +from typing import Awaitable, Protocol, Union, Optional, runtime_checkable + + +__all__: list[str] = ["Keypair"] + + +# For reference only +# class KeypairType: +# """ +# Type of cryptography, used in `Keypair` instance to encrypt and sign data +# +# * ED25519 = 0 +# * SR25519 = 1 +# * ECDSA = 2 +# +# """ +# ED25519 = 0 +# SR25519 = 1 +# ECDSA = 2 + + +@runtime_checkable +class Keypair(Protocol): + @property + def crypto_type(self) -> int: ... + + @property + def public_key(self) -> Optional[bytes]: ... + + @property + def ss58_address(self) -> str: ... + + @property + def ss58_format(self) -> int: ... + + def sign(self, data: Union[bytes, str]) -> Union[bytes, Awaitable[bytes]]: ... diff --git a/async_substrate_interface/sync_substrate.py b/async_substrate_interface/sync_substrate.py index 01f5fdb..21664d4 100644 --- a/async_substrate_interface/sync_substrate.py +++ b/async_substrate_interface/sync_substrate.py @@ -3,8 +3,6 @@ from hashlib import blake2b from typing import Optional, Union, Callable, Any -from bittensor_wallet.keypair import Keypair -from bittensor_wallet.utils import SS58_FORMAT from bt_decode import MetadataV15, PortableRegistry, decode as decode_by_type_string from scalecodec import ( GenericCall, @@ -17,12 +15,14 @@ from websockets.sync.client import connect from websockets.exceptions import ConnectionClosed +from async_substrate_interface.const import SS58_FORMAT from async_substrate_interface.errors import ( ExtrinsicNotFound, SubstrateRequestException, BlockNotFound, MaxRetriesExceeded, ) +from async_substrate_interface.protocols import Keypair from async_substrate_interface.types import ( SubstrateMixin, RuntimeCache, diff --git a/async_substrate_interface/types.py b/async_substrate_interface/types.py index 261f73a..5a83895 100644 --- a/async_substrate_interface/types.py +++ b/async_substrate_interface/types.py @@ -7,12 +7,12 @@ from typing import Optional, Union, Any from bt_decode import PortableRegistry, encode as encode_by_type_string -from bittensor_wallet.utils import SS58_FORMAT from scalecodec import ss58_encode, ss58_decode, is_valid_ss58_address from scalecodec.base import RuntimeConfigurationObject, ScaleBytes from scalecodec.type_registry import load_type_registry_preset from scalecodec.types import GenericCall, ScaleType, MultiAccountId +from .const import SS58_FORMAT from .utils import json diff --git a/pyproject.toml b/pyproject.toml index 8fe5ee8..f5b7cec 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,6 @@ keywords = ["substrate", "development", "bittensor"] dependencies = [ "wheel", "asyncstdlib~=3.13.0", - "bittensor-wallet>=2.1.3", "bt-decode==v0.6.0", "scalecodec~=1.2.11", "websockets>=14.1",