feat: add more options for wallets
This commit is contained in:
@@ -81,7 +81,7 @@ class Settings(BaseSettings):
|
||||
RATE_LIMIT_WINDOW: int = 60
|
||||
|
||||
LOG_LEVEL: Literal['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'] = 'INFO'
|
||||
LOG_FORMAT: Literal['JSON', 'TEXT'] = 'TEXT'
|
||||
LOG_FORMAT: Literal['JSON', 'TEXT'] = 'JSON'
|
||||
|
||||
@field_validator('VAULT_ADDR', mode='before')
|
||||
@classmethod
|
||||
|
||||
@@ -43,6 +43,14 @@ class DerivedWallet:
|
||||
derivation_path: str
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class DerivedSecretKey:
|
||||
chain: str
|
||||
address: str
|
||||
derivation_path: str
|
||||
private_key: str
|
||||
|
||||
|
||||
class CryptoNotReadyError(RuntimeError):
|
||||
pass
|
||||
|
||||
@@ -151,6 +159,87 @@ def derive_all_addresses(mnemonic: str) -> list[DerivedWallet]:
|
||||
]
|
||||
|
||||
|
||||
def derive_all_private_keys(mnemonic: str) -> list[DerivedSecretKey]:
|
||||
seed_bytes = Bip39SeedGenerator(mnemonic).Generate()
|
||||
|
||||
eth_ctx = Bip44.FromSeed(seed_bytes, Bip44Coins.ETHEREUM)
|
||||
eth_node = (
|
||||
eth_ctx.Purpose()
|
||||
.Coin()
|
||||
.Account(0)
|
||||
.Change(Bip44Changes.CHAIN_EXT)
|
||||
.AddressIndex(0)
|
||||
)
|
||||
eth_addr = eth_node.PublicKey().ToAddress()
|
||||
eth_pk = eth_node.PrivateKey().Raw().ToHex()
|
||||
|
||||
btc_ctx = Bip84.FromSeed(seed_bytes, Bip84Coins.BITCOIN)
|
||||
btc_node = (
|
||||
btc_ctx.Purpose()
|
||||
.Coin()
|
||||
.Account(0)
|
||||
.Change(Bip44Changes.CHAIN_EXT)
|
||||
.AddressIndex(0)
|
||||
)
|
||||
btc_addr = btc_node.PublicKey().ToAddress()
|
||||
btc_pk = btc_node.PrivateKey().Raw().ToHex()
|
||||
|
||||
trx_ctx = Bip44.FromSeed(seed_bytes, Bip44Coins.TRON)
|
||||
trx_node = (
|
||||
trx_ctx.Purpose()
|
||||
.Coin()
|
||||
.Account(0)
|
||||
.Change(Bip44Changes.CHAIN_EXT)
|
||||
.AddressIndex(0)
|
||||
)
|
||||
trx_addr = trx_node.PublicKey().ToAddress()
|
||||
trx_pk = trx_node.PrivateKey().Raw().ToHex()
|
||||
|
||||
sol_ctx = Bip44.FromSeed(seed_bytes, Bip44Coins.SOLANA)
|
||||
sol_node = (
|
||||
sol_ctx.Purpose()
|
||||
.Coin()
|
||||
.Account(0)
|
||||
.Change(Bip44Changes.CHAIN_EXT)
|
||||
.AddressIndex(0)
|
||||
)
|
||||
sol_addr = sol_node.PublicKey().ToAddress()
|
||||
sol_pk = sol_node.PrivateKey().Raw().ToHex()
|
||||
|
||||
return [
|
||||
DerivedSecretKey(
|
||||
chain='ETH',
|
||||
address=eth_addr,
|
||||
derivation_path=DERIVATION_PATHS['ETH'],
|
||||
private_key=eth_pk,
|
||||
),
|
||||
DerivedSecretKey(
|
||||
chain='BSC',
|
||||
address=eth_addr,
|
||||
derivation_path=DERIVATION_PATHS['BSC'],
|
||||
private_key=eth_pk,
|
||||
),
|
||||
DerivedSecretKey(
|
||||
chain='BTC',
|
||||
address=btc_addr,
|
||||
derivation_path=DERIVATION_PATHS['BTC'],
|
||||
private_key=btc_pk,
|
||||
),
|
||||
DerivedSecretKey(
|
||||
chain='TRX',
|
||||
address=trx_addr,
|
||||
derivation_path=DERIVATION_PATHS['TRX'],
|
||||
private_key=trx_pk,
|
||||
),
|
||||
DerivedSecretKey(
|
||||
chain='SOL',
|
||||
address=sol_addr,
|
||||
derivation_path=DERIVATION_PATHS['SOL'],
|
||||
private_key=sol_pk,
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
def encrypt_mnemonic(plaintext: str) -> str:
|
||||
if _master_key is None:
|
||||
raise CryptoNotReadyError('Crypto service not ready')
|
||||
|
||||
Reference in New Issue
Block a user