Keyring Wallets¶
Notice
The keyring manager contains methods for easily managing wallet operations.
A wallet class stores one or more accounts associated with the wallet type. Each account is stored as a keyring. There’s two types of accounts stored. Hierarchical deterministic or simple keyring (see, HdKeyring). In addition, a wallet contains a list of supported assets, which can be imported to into the asset library.
Every wallet type created will increment the sid by 1, resulting in an unique wallet id (e.g. MCW1, SAW2, etc.)
Multi Chain Wallet¶
This wallet is a hierarchical deterministic keyring type. Which means private keys (accounts) are generated from a master/root seed. Thus, supports multiple chains and accounts per wallet.
Parameters
Parameter |
Type |
Description |
|---|---|---|
type |
|
|
id |
|
Wallet type plus appended wallet iteration (e.g. |
supported_assets |
|
Can be empty |
keyrings |
|
|
label |
|
The name of the wallet. Maximum 12 characters. |
mnemonic |
|
12 words seed phrase. |
Create Multi Chain Wallet¶
Parameters
Parameter |
Type |
Description |
|---|---|---|
label |
|
The name of the wallet, for example |
mnemonic |
|
12 word seed phrase. |
rings |
|
A |
Example Usage
from pypergraph.keyring import MultiChainWallet
wallet = MultiChainWallet()
wallet.create(label="Jane Doe 1")
This will store a list of hierarchical deterministic keyrings, one DAG and one ETH.
Get Wallet State¶
Example Usage
from pypergraph.keyring import MultiChainWallet
wallet = MultiChainWallet()
wallet.create(label="Jane Doe 1")
state = wallet.get_state()
Return
{
'id': 'MCW1',
'type': 'MCW',
'label': "Jane Doe 1",
'supported_assets': [],
'accounts': [
{
'address': 'DAG1...', # The DAG wallet address associated with the HD account
'network': 'Constellation',
'tokens': []
},
{
'address': '0x1A...', # The ETH wallet address associated with the HD account
'network': 'Ethereum',
'tokens': ['0xa393473d64d2F9F026B60b6Df7859A689715d092']
}
]
}
Full List of Multi Chain Wallet Methods¶
- class pypergraph.keyring.wallets.multi_chain_wallet.MultiChainWallet(*, type: str = 'MCW', id: str = None, supported_assets: List[str] = [], label: Annotated[str | None, MaxLen(max_length=12)] = None, keyrings: List[HdKeyring] = [], mnemonic: str | None = None)[source]¶
Bases:
BaseModel- create(label: str, mnemonic: str | None = None, rings: list | None = None)[source]¶
If mnemonic is set, restore the wallet. Else, generate mnemonic and create new wallet.
- Parameters:
label – Name of the wallet.
mnemonic – Seed phrase.
rings – Keyrings.
- get_account_by_address(address: str) DagAccount | EthAccount[source]¶
- get_accounts() List[DagAccount | EthAccount][source]¶
Get all MCW accounts.
- Returns:
List of accounts with signing key.
- id: str¶
- label: str | None¶
- mnemonic: str | None¶
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- set_label(label: str)[source]¶
Set the name of the wallet.
- Parameters:
label – Sets the name of the wallet.
- supported_assets: List[str]¶
- type: str¶
Multi Account Wallet¶
This wallet is a hierarchical deterministic wallet type. Which means private keys (accounts) are generated from a master/root seed. Thus, supports multiple chains and accounts per wallet. This specific wallet type creates a number of accounts from the mnemonic seed phrase.
Parameters
Parameter |
Type |
Description |
|---|---|---|
type |
|
|
id |
|
Wallet type plus appended wallet iteration (e.g. |
supported_assets |
|
Can be empty |
keyring |
|
|
label |
|
The name of the wallet. Maximum 12 characters. |
network |
|
|
mnemonic |
|
12 words seed phrase. |
Create Multi Account Wallet¶
Parameters
Parameter |
Type |
Description |
|---|---|---|
label |
|
The name of the wallet, for example |
mnemonic |
|
12 word seed phrase. |
num_of_accounts |
|
Number of BIP44 indexes (accounts) to create using the mnemonic phrase. |
network |
|
|
Example Usage
from pypergraph.keyring import MultiAccountWallet
wallet = MultiAccountWallet()
wallet.create(network="Constellation", label="Jane Doe 4", num_of_accounts=3)
state = wallet.get_state()
Return
{
'id': 'MAW4',
'type': 'MAW',
'label': 'Jane Doe 4',
'supported_assets': ['DAG'],
'accounts': [
{
'address': 'DAG1ZHaLNLDJoV7yAvjbvLTTKXzHX1A18xEd2zoc', # DAG address corresponding to mnemonic phrase BIP44 index 0
'supported_assets': ['DAG']
},
{
'address': 'DAG0mUMDdcQrNnzvZJ7RiY7C5LUUiPBh8YvnAffe', # ... BIP44 index 1
'supported_assets': ['DAG']
},
{
'address': 'DAG4q9htCP4CuBo2iPDVRMHxF5cR7fHM4ovfukQe', # ... BIP44 index 2
'supported_assets': ['DAG']
}
]
}
Full List of Multi Chain Wallet Methods¶
- class pypergraph.keyring.wallets.multi_account_wallet.MultiAccountWallet(*, type: str = 'MAW', id: str = None, supported_assets: List[str] = [], label: Annotated[str | None, MaxLen(max_length=12)] = None, keyring: HdKeyring = None, mnemonic: str | None = None, network: str = None)[source]¶
Bases:
BaseModel- create(network: str, label: str, num_of_accounts: int = 1, mnemonic: str | None = None)[source]¶
Creates a wallet with a keyring of hierarchical deterministic accounts based on the number BIP44 indexes (num_of_accounts).
- Parameters:
network – “Constellation” or “Ethereum”.
label – Name of the wallet.
num_of_accounts – Number of BIP44 indexes (accounts) to create.
mnemonic – Mnemonic phrase.
- deserialize(label: str, network: str, secret: str, num_of_accounts: int, rings: List | None = None)[source]¶
- get_account_by_address(address: str)[source]¶
Get the account matching the specified address.
- Parameters:
address – The address for the wanted account.
- get_accounts() List[source]¶
Get list of MAW accounts.
- Returns:
List of MAW accounts with signing key.
- id: str¶
- label: str | None¶
- mnemonic: str | None¶
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- network: str¶
- remove_account(account)[source]¶
Remove a specific account.
- Parameters:
account – The account to be removed.
- supported_assets: List[str]¶
- type: str¶
Single Account Wallet¶
This wallet is not a hierarchical deterministic wallet type. Which means the private keys are not generated from a master/root seed. Does not support multiple chains and accounts per wallet secret, one private key per account and/or chain.
Parameters
Parameter |
Type |
Description |
|---|---|---|
type |
|
|
id |
|
Wallet type plus appended wallet iteration (e.g. |
supported_assets |
|
Can be empty |
keyring |
|
|
network |
|
|
label |
|
The name of the wallet. Maximum 12 characters. |
Create Single Account Wallet¶
Parameters
Parameter |
Type |
Description |
|---|---|---|
label |
|
The name of the wallet, for example |
private_key |
|
The private key you wish to create an account/wallet for. |
network |
|
|
Example Usage
from pypergraph.keyring import SingleAccountWallet
wallet = SingleAccountWallet()
wallet.create(label="Jane Doe 2")
state = wallet.get_state()
Return
{
'id': 'SAW2',
'type': 'SAW',
'label': 'Jane 2',
'supported_assets': ['DAG'],
'accounts': [
{
'address': 'DAG6pmeo33ykpedwVaZqnQo7Kz7x4HUuL9PiqdJH', # The DAG address associated with the wallet/account private key
'network': 'Constellation',
'tokens': []
}
]
}
Full List of Single Account Wallet Methods¶
- class pypergraph.keyring.wallets.single_account_wallet.SingleAccountWallet(*, type: str = 'SAW', id: str = None, supported_assets: ~typing.List = <factory>, label: ~typing.Annotated[str | None, ~annotated_types.MaxLen(max_length=12)] = None, keyring: ~pypergraph.keyring.keyrings.simple_keyring.SimpleKeyring | None = None, network: str | None = None)[source]¶
Bases:
BaseModel- create(network: str, label: str, private_key: str = None)[source]¶
Initiates the creation of a new single key wallet.
- Parameters:
network – “Constellation” or “Ethereum”.
private_key – Optional, the private key to create account for. Leaving empty will create a new account from new private key.
label – The name of the wallet.
- export_secret_key() str[source]¶
Get the privat key.
- Returns:
Private key in hexadecimal string format.
- get_account_by_address(address: str) DagAccount | EthAccount[source]¶
Get the account matching a specific address.
- Parameters:
address – The account address.
- Returns:
The account matching the address.
- get_accounts() List[DagAccount | EthAccount][source]¶
- id: str¶
- keyring: SimpleKeyring | None¶
- label: str | None¶
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- network: str | None¶
- supported_assets: List¶
- type: str¶
Multi Key Wallet¶
This wallet is not a hierarchical deterministic wallet type. Which means the private keys are not generated from a master/root seed.
This wallet type does not automatically generate a new account/wallet. Instead, simple accounts (private key accounts)
are imported into the wallet manually after creation. For each import a label and network is provided and the imported
private key is added to the list of keyrings.
Parameters
Parameter |
Type |
Description |
|---|---|---|
type |
|
|
id |
|
Wallet type plus appended wallet iteration (e.g. |
supported_assets |
|
Can be empty |
keyrings |
|
|
network |
|
|
label |
|
The name of the wallet. Maximum 12 characters. |
Create Multi Key Wallet¶
Creates an empty wallet by default. Manual import necessary, see method below.
Parameters
Parameter |
Type |
Description |
|---|---|---|
label |
|
The name of the wallet, for example |
network |
|
|
Example Usage
from pypergraph.keyring import MultiKeyWallet
wallet = MultiKeyWallet()
wallet.create(label="Jane Doe 3", network="Constellation")
wallet.import_account(private_key="469f...", label="Account 1")
wallet.get_state()
Return
{
'id': 'MKW3',
'type': 'MKW',
'label': 'Jane Doe 3',
'network': 'Constellation',
'supported_assets': ['DAG'],
'accounts': [
{
'address': 'DAG6s6X8BGsLysM6yGtntpkuwKo52QLbTibP6uCR', # The DAG address associated with the private key
'label': 'Account 1'
}
]
}
Full List of Multi Key Wallet Methods¶
- class pypergraph.keyring.wallets.multi_key_wallet.MultiKeyWallet(*, type: str = 'MKW', id: str = None, supported_assets: List[str] = [], label: Annotated[str | None, MaxLen(max_length=12)] = None, keyrings: List[SimpleKeyring] = [], network: str | None = None)[source]¶
Bases:
BaseModel- create(network: str, label: str)[source]¶
Create new multi key wallet. Accounts must be imported.
- Parameters:
network – “Constellation” or “Ethereum”
label – The wallet name.
- get_account_by_address(address: str) DagAccount | EthAccount[source]¶
Get the account matching the specified address.
- Parameters:
address – The address matching the account.
- get_accounts() List[DagAccount | EthAccount][source]¶
Get a list of all MKW accounts.
- Returns:
List of imported MKW accounts.
- id: str¶
- import_account(private_key: str, label: str) DagAccount | EthAccount[source]¶
Imports an account using private key, sets a label, creates a keyring and adds it to the list of keyrings.
- Parameters:
private_key – The private key of the account to import.
label – Name of the account.
- Returns:
The account.
- keyrings: List[SimpleKeyring]¶
- label: str | None¶
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- network: str | None¶
- supported_assets: List[str]¶
- type: str¶