pypergraph.keyring package

Subpackages

Submodules

pypergraph.keyring.encryptor module

class pypergraph.keyring.encryptor.AsyncAesGcmEncryptor[source]

Bases: object

async decrypt(password: str, vault: Dict[str, Any]) Dict[str, Any][source]

Secure decryption with full validation

async encrypt(password: str, data: Dict[str, Any]) Dict[str, Any][source]

Securely encrypt wallet data using: - Argon2id for memory-hard KDF - AES-256-GCM for authenticated encryption - HKDF for key separation - Random nonce with HMAC integrity

class pypergraph.keyring.encryptor.SecurityConstants[source]

Bases: object

Cryptographic parameters meeting wallet security standards

AES_KEY_SIZE = 32
ARGON_MEMORY_COST = 65536
ARGON_PARALLELISM = 1
ARGON_TIME_COST = 3
HMAC_KEY_SIZE = 32
NONCE_SIZE = 12
SALT_SIZE = 32
VERSION = 1
exception pypergraph.keyring.encryptor.SecurityException[source]

Bases: Exception

async pypergraph.keyring.encryptor.main()[source]

pypergraph.keyring.manager module

class pypergraph.keyring.manager.KeyringManager(storage_file_path: str | None = None)[source]

Bases: object

check_password(password) bool[source]
async clear_wallets()[source]

Clear wallet cache.

async create_multi_chain_hd_wallet(label: str | None = None, seed: str | None = None) MultiChainWallet[source]

This is the next step in creating or restoring a wallet, by default.

Parameters:
  • label – Wallet name.

  • seed – Seed phrase.

Returns:

async create_or_restore_vault(password: str, label: str | None = None, seed: str | None = None) MultiChainWallet[source]

First step, creating or restoring a wallet. This is the default wallet type when creating a new wallet.

Parameters:
  • label – The name of the wallet.

  • seed – Seed phrase.

  • password – A string of characters.

Returns:

async create_single_account_wallet(label: str, private_key: str, network: Constellation | Ethereum | None = None) SingleAccountWallet[source]
static generate_mnemonic() str[source]
get_accounts() List[DagAccount | EthAccount][source]
get_wallet_by_id(id: str) MultiChainWallet | SingleAccountWallet | MultiAccountWallet | MultiKeyWallet[source]
get_wallet_for_account(address: str) MultiChainWallet | SingleAccountWallet | MultiAccountWallet | MultiKeyWallet[source]
is_unlocked() bool[source]
async login(password: str)[source]
async logout()[source]
async remove_account(address)[source]
remove_empty_wallets()[source]
set_password(password: str)[source]

Will enforce basic restrictions on password creation

set_wallet_label(wallet_id: str, label: str)[source]

Module contents

pypergraph.keyring.Encryptor

alias of AsyncAesGcmEncryptor

class pypergraph.keyring.HdKeyring(*, accounts: ~typing.List[~pypergraph.keyring.accounts.ecdsa_account.EcdsaAccount] = <factory>, hd_path: str | None = None, mnemonic: str | None = None, extended_key: str | None = None, root_key: ~bip32utils.BIP32Key.BIP32Key | None = None, network: str | None = None)[source]

Bases: BaseModel

Hierarchical Deterministic Keyring: BIP32

accounts: List[EcdsaAccount]
add_account_at(index: int = 0) DagAccount | EthAccount | EcdsaAccount[source]

Add account class object with a signing key to the keyring being constructed.

Parameters:

index – Account number (bipIndex).

Returns:

EcdsaAccount or DagAccount class object (dag_keyring.accounts) with signing key at self.wallet.

create(mnemonic: str, hd_path: str, network: str, number_of_accounts: int = 1) Self[source]

Create a hierarchical deterministic keyring.

Parameters:
  • mnemonic – Mnemonic phrase.

  • hd_path – The derivation path for the coin chain (without index).

  • network – The network associated with the coin.

  • number_of_accounts – How many accounts (indexes) to create.

Returns:

Hierarchical deterministic keyring.

create_accounts(number_of_accounts: int = 0) List[Dict][source]

When adding an account (after accounts have been removed), it will add back the ones removed first.

Parameters:

number_of_accounts – The number of accounts to create.

Returns List[dict]:

A list of dictionaries with bip44 index.

create_from_extended_key(extended_key: str, network: NetworkId, number_of_accounts: int) Self[source]
deserialize(data: dict)[source]

Deserialize then add account (bip44_index) to the keyring being constructed.

Parameters:

data

export_account(account) str[source]
extended_key: str | None
get_account_by_address(address: str) DagAccount | EthAccount[source]
get_accounts() List[source]
get_extended_public_key() str[source]
get_hd_path() str[source]
get_network() str[source]
hd_path: str | None
mnemonic: str | None
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

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]
remove_last_added_account()[source]
root_key: BIP32Key | None
class pypergraph.keyring.KeyringAssetInfo(id: str, label: str, symbol: str, decimals: int, native: bool | None = None, network: str | None = None, address: str | None = None)[source]

Bases: object

address: str | None = None
decimals: int
id: str
label: str
native: bool | None = None
network: str | None = None
symbol: str
class pypergraph.keyring.KeyringManager(storage_file_path: str | None = None)[source]

Bases: object

check_password(password) bool[source]
async clear_wallets()[source]

Clear wallet cache.

async create_multi_chain_hd_wallet(label: str | None = None, seed: str | None = None) MultiChainWallet[source]

This is the next step in creating or restoring a wallet, by default.

Parameters:
  • label – Wallet name.

  • seed – Seed phrase.

Returns:

async create_or_restore_vault(password: str, label: str | None = None, seed: str | None = None) MultiChainWallet[source]

First step, creating or restoring a wallet. This is the default wallet type when creating a new wallet.

Parameters:
  • label – The name of the wallet.

  • seed – Seed phrase.

  • password – A string of characters.

Returns:

async create_single_account_wallet(label: str, private_key: str, network: Constellation | Ethereum | None = None) SingleAccountWallet[source]
static generate_mnemonic() str[source]
get_accounts() List[DagAccount | EthAccount][source]
get_wallet_by_id(id: str) MultiChainWallet | SingleAccountWallet | MultiAccountWallet | MultiKeyWallet[source]
get_wallet_for_account(address: str) MultiChainWallet | SingleAccountWallet | MultiAccountWallet | MultiKeyWallet[source]
is_unlocked() bool[source]
async login(password: str)[source]
async logout()[source]
async remove_account(address)[source]
remove_empty_wallets()[source]
set_password(password: str)[source]

Will enforce basic restrictions on password creation

set_wallet_label(wallet_id: str, label: str)[source]
class pypergraph.keyring.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
class pypergraph.keyring.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
class pypergraph.keyring.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
class pypergraph.keyring.SimpleKeyring(*, account: EcdsaAccount = None, network: str = 'Constellation')[source]

Bases: BaseModel

account: EcdsaAccount
add_account_at(index: int)[source]

Not supported for SimpleKeyring

create_for_network(network, private_key: str) Self[source]
deserialize(network: str, accounts: list)[source]
get_account_by_address(address: str)[source]

Get the account matching the specified address.

Returns:

Account class or None is nothing matches.

get_accounts() List[DagAccount | EthAccount | Any][source]

Get all accounts in the simple keyring.

Returns:

List of account classes (only one).

get_state()[source]
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
remove_account(account)[source]

Not supported for SimpleKeyring

class pypergraph.keyring.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