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

str

MCW.

id

str

Wallet type plus appended wallet iteration (e.g. MCW1).

supported_assets

[] (default) or list of str

Can be empty DAG or ETH, depended on the account type associated with imported asset (see: keyring accounts).

keyrings

[] (default) or list of HdKeyring

label

None (default) or str

The name of the wallet. Maximum 12 characters.

mnemonic

None (default) or str

12 words seed phrase.


Create Multi Chain Wallet

Parameters

Parameter

Type

Description

label

str

The name of the wallet, for example Jane Doe 1.

mnemonic

None (default) or``str``

12 word seed phrase. None will create a new wallet from a new generated mnemonic seed.

rings

None (default) or list of HdKeyring objects.

A HdKeyring object is created from the mnemonic seed phrase, hierarchical deterministic path and the number of accounts (see: keyring accounts).

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

compute_id()[source]

Automatically computes the id based on injected SID value.

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.

deserialize(label: str, secret: str, rings: list | None = None)[source]
export_secret_key() str[source]

Export mnemonic seed phrase.

Returns:

Mnemonic seed phrase.

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.

get_label() str[source]

Get the name on the wallet.

Returns:

The name of the wallet.

static get_network()[source]
get_state() Dict[str, Any][source]
id: str
static import_account()[source]

Importing MCW account is not supported.

keyrings: List[HdKeyring]
label: str | None
mnemonic: str | None
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_serialize() Dict[str, Any][source]
static remove_account()[source]

Remove MCW not supported.

static reset_sid()[source]
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

str

MAW.

id

str

Wallet type plus appended wallet iteration (e.g. MAW2).

supported_assets

[] (default) or list of str

Can be empty DAG or ETH, depended on the account type associated with imported asset (see: keyring accounts).

keyring

None (default) or HdKeyring

label

None (default) or str

The name of the wallet. Maximum 12 characters.

network

None (default) or str

Constellation or Ethereum.

mnemonic

None (default) or str

12 words seed phrase.


Create Multi Account Wallet

Parameters

Parameter

Type

Description

label

str

The name of the wallet, for example Jane Doe 2.

mnemonic

None (default) or str

12 word seed phrase. None will create a new wallet from a new generated mnemonic seed.

num_of_accounts

int = 1 (default)

Number of BIP44 indexes (accounts) to create using the mnemonic phrase.

network

str

Constellation or Ethereum.

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

add_account()[source]
compute_id()[source]

Automatically computes the id based on injected SID value.

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]
export_secret_key() str[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.

get_label() str[source]

Get the name of the wallet.

Returns:

The wallet name.

get_network() str[source]
get_state() Dict[str, Any][source]
id: str
static import_account()[source]

Importing is not supported.

keyring: HdKeyring
label: str | None
mnemonic: str | None
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_serialize() Dict[str, Any][source]

Returns a serialized version of the object.

network: str
remove_account(account)[source]

Remove a specific account.

Parameters:

account – The account to be removed.

static reset_sid()[source]
set_label(val: str)[source]

Sets the name of the wallet.

Parameters:

val – The name of the wallet.

set_num_of_accounts(num: int)[source]
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

str

SAW.

id

str

Wallet type plus appended wallet iteration (e.g. SAW3).

supported_assets

[] (default) or list of str

Can be empty DAG or ETH, depended on the account type associated with imported asset (see: keyring accounts).

keyring

None (default) or SimpleKeyring

network

None (default) or str

Constellation or Ethereum.

label

None (default) or str

The name of the wallet. Maximum 12 characters.


Create Single Account Wallet

Parameters

Parameter

Type

Description

label

str

The name of the wallet, for example Jane Doe 3.

private_key

None (default) or str

The private key you wish to create an account/wallet for. None will create a new wallet from a new generated mnemonic seed.

network

str

Constellation or Ethereum.

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

compute_id()[source]

Automatically computes the id based on injected SID value.

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.

deserialize(network: str, label: str, secret: str)[source]
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]
get_label() str[source]

Get the name of the wallet.

Returns:

The wallet name.

get_network() str[source]
get_state() Dict[str, Any][source]
id: str
static import_account()[source]

Not supported for SingleAccountWallet.

keyring: SimpleKeyring | None
label: str | None
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_serialize() Dict[str, Any][source]
network: str | None
remove_account(account)[source]

Not supported by SAW.

static reset_sid()[source]
set_label(label: str)[source]

Set the name of the wallet.

Parameters:

label – The wallet name.

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

str

MKW.

id

str

Wallet type plus appended wallet iteration (e.g. MKW4).

supported_assets

[] (default) or list of str

Can be empty DAG or ETH, depended on the account type associated with imported asset (see: keyring accounts).

keyrings

[] (default) or list of SimpleKeyring``

network

None (default) or str

Constellation or Ethereum.

label

None (default) or str

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

str

The name of the wallet, for example Jane Doe 4.

network

str

Constellation or Ethereum.

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

compute_id()[source]

Automatically computes the id based on injected SID value.

create(network: str, label: str)[source]

Create new multi key wallet. Accounts must be imported.

Parameters:
  • network – “Constellation” or “Ethereum”

  • label – The wallet name.

deserialize(label: str, network: str, accounts: list | None = None)[source]
static export_secret_key()[source]

Not supported by MKW.

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.

get_label() str[source]

Get the name of the wallet.

Returns:

The wallet name.

static get_network()[source]

Not supported by MKW.

get_state() Dict[str, Any][source]
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].

model_serialize() Dict[str, Any][source]
network: str | None
static remove_account()[source]

Not supported by MKW.

static reset_sid()[source]
set_label(val: str)[source]

Set the name of the wallet.

Parameters:

val – The wallet name.

supported_assets: List[str]
type: str