Skip to content

Commit

Permalink
feat: wallet mnemonic import (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
stat authored Jan 8, 2025
1 parent 34cc35c commit faf1ed0
Show file tree
Hide file tree
Showing 5 changed files with 1,772 additions and 1,494 deletions.
5 changes: 4 additions & 1 deletion cdp-langchain/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

## Unreleased

- Bump dependency `cdp-agentkit-core` to version `0.0.7`.
- Bump dependency `cdp-sdk` to version `0.13.0`.
- Wallet mnemonic phrase import

## [0.0.8] - 2024-12-06

### Added

- Bump dependency `cdp-agentkit-core` to version `0.0.6`.
- Bump dependency `cdp-sdk` to version `0.12.0`.


## [0.0.7] - 2024-11-16

### Added
Expand Down
7 changes: 6 additions & 1 deletion cdp-langchain/cdp_langchain/utils/cdp_agentkit_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from langchain_core.utils import get_from_dict_or_env
from pydantic import BaseModel, model_validator

from cdp import Wallet
from cdp import MnemonicSeedPhrase, Wallet
from cdp_langchain import __version__
from cdp_langchain.constants import CDP_LANGCHAIN_DEFAULT_SOURCE

Expand All @@ -29,6 +29,7 @@ def validate_environment(cls, values: dict) -> Any:
cdp_api_key_private_key = get_from_dict_or_env(
values, "cdp_api_key_private_key", "CDP_API_KEY_PRIVATE_KEY"
).replace("\\n", "\n")
mnemonic_phrase = get_from_dict_or_env(values, "mnemonic_phrase", "MNEMONIC_PHRASE", "")
network_id = get_from_dict_or_env(values, "network_id", "NETWORK_ID", "base-sepolia")
wallet_data_json = values.get("cdp_wallet_data")

Expand All @@ -49,12 +50,16 @@ def validate_environment(cls, values: dict) -> Any:
if wallet_data_json:
wallet_data = WalletData.from_dict(json.loads(wallet_data_json))
wallet = Wallet.import_data(wallet_data)
elif mnemonic_phrase:
phrase = MnemonicSeedPhrase(mnemonic_phrase)
wallet = Wallet.import_wallet(phrase)
else:
wallet = Wallet.create(network_id=network_id)

values["wallet"] = wallet
values["cdp_api_key_name"] = cdp_api_key_name
values["cdp_api_key_private_key"] = cdp_api_key_private_key
values["mnemonic_phrase"] = mnemonic_phrase
values["network_id"] = network_id

return values
Expand Down
Loading

0 comments on commit faf1ed0

Please sign in to comment.