Skip to content

Commit

Permalink
Merge pull request hummingbot#7118 from peterwilli/feat/injective_v2_…
Browse files Browse the repository at this point in the history
…seed_phrase_connect

Feat/injective v2 seed phrase connect
  • Loading branch information
rapcmia authored Jul 17, 2024
2 parents 846ad61 + 60322f9 commit ba012e5
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion hummingbot/connector/exchange/injective_v2/injective_v2_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from abc import ABC, abstractmethod
from decimal import Decimal
from typing import TYPE_CHECKING, Dict, List, Optional, Union
Expand All @@ -12,6 +13,7 @@
TransactionFeeCalculator,
)
from pyinjective.core.network import Network
from pyinjective.wallet import PrivateKey

from hummingbot.client.config.config_data_types import BaseClientModel, BaseConnectorConfigMap, ClientFieldData
from hummingbot.connector.exchange.injective_v2 import injective_constants as CONSTANTS
Expand Down Expand Up @@ -254,6 +256,9 @@ def rate_limits(self) -> List[RateLimit]:
InjectiveCustomNetworkMode.Config.title: InjectiveCustomNetworkMode,
}

# Captures a 12 or 24-word BIP39 seed phrase
RE_SEED_PHRASE = re.compile(r"^(?:[a-z]+(?: [a-z]+){11}|[a-z]+(?: [a-z]+){23})$")


class InjectiveAccountMode(BaseClientModel, ABC):

Expand All @@ -272,7 +277,7 @@ class InjectiveDelegatedAccountMode(InjectiveAccountMode):
private_key: SecretStr = Field(
default=...,
client_data=ClientFieldData(
prompt=lambda cm: "Enter your Injective trading account private key",
prompt=lambda cm: "Enter your Injective trading account private key or seed phrase",
is_secure=True,
is_connect_key=True,
prompt_on_new=True,
Expand Down Expand Up @@ -300,6 +305,16 @@ class InjectiveDelegatedAccountMode(InjectiveAccountMode):
),
)

@validator("private_key", pre=True)
def validate_network(cls, v: str):
# Both seed phrase and hex private keys supported
if isinstance(v, str):
v = v.strip()
if RE_SEED_PHRASE.match(v):
private_key = PrivateKey.from_mnemonic(v)
return private_key.to_hex()
return v

class Config:
title = "delegate_account"

Expand Down

0 comments on commit ba012e5

Please sign in to comment.