pypergraph.keystore package¶
Subpackages¶
Submodules¶
pypergraph.keystore.keystore module¶
- class pypergraph.keystore.keystore.KeyStore[source]¶
Bases:
objectMethods dealing with keys.
- DATA_SIGN_PREFIX = '\x19Constellation Signed Data:\n'¶
- PERSONAL_SIGN_PREFIX = '\x19Constellation Signed Message:\n'¶
- data_sign(private_key, msg: dict, prefix: bool | str = True, encoding: Literal['base64'] | Callable[[dict], str] | None = None) Tuple[str, str][source]¶
Encode message according to serializeUpdate on your template module l1.
- param private_key:
- param msg:
Dictionary (the content of ‘value’ in a SignedTransaction).
- param prefix:
Enable or disable the default prefix ‘Constellation Signed Data:
- ‘ to the encoded msg or inject custom string.
- param encoding:
Can be None (default), ‘base64’ or a custom encoding function.
- return:
signature, transaction hash.
- async static decrypt_phrase(keystore: V3Keystore, password: str) str[source]¶
Can be used to decrypt the phrase using password.
- Parameters:
keystore
password
- Returns:
- static derive_account_from_master_key(master_key: BIP32Key, index: int) str[source]¶
Derive HD private key from master key.
- Parameters:
master_key
index
- Returns:
- encode_data(msg: dict, prefix: bool | str = True, encoding: Literal['base64'] | Callable[[dict], str] | None = None) str[source]¶
Encode custom data transaction for signing or signature verification.
- param msg:
Dictionary (the content of ‘value’ in a SignedTransaction).
- param prefix:
Enable or disable the default prefix ‘Constellation Signed Data:
- ‘ to the encoded msg.
- param encoding:
Can be None (default), ‘base64’ or a custom encoding function.
- return:
Encoded data transaction.
- async static encrypt_phrase(phrase: str, password: str) V3Keystore[source]¶
Can be used to encrypt the phrase using password.
- Parameters:
phrase
password
- Returns:
- encrypt_private_key(password: str, private_key: str | None = None) Dict[str, Any][source]¶
Can be stored (written to disk) and transferred.
- Parameters:
private_key
password
- Returns:
Dictionary, use json.dumps()
- static get_dag_address_from_public_key(public_key: str) str[source]¶
- Parameters:
public_key – The private key as a hexadecimal string.
- Returns:
The DAG address corresponding to the public key (node ID).
- static get_master_key_from_mnemonic(phrase: str, derivation_path: str = "m/44'/1137'/0'/0")[source]¶
Master key can be used to derive HD keys.
- Parameters:
phrase
derivation_path
- Returns:
- static get_private_key_from_mnemonic(phrase: str, derivation_path="m/44'/1137'/0'/0") str[source]¶
Get private key from phrase. Returns the first account.
- Parameters:
phrase
derivation_path
- Returns:
Private key as hexadecimal string
- static get_public_key_from_private(private_key: str) str[source]¶
- Parameters:
private_key
- Returns:
Public key (Node ID)
- static prepare_tx(amount: int, to_address: str, from_address: str, last_ref: TransactionReference, fee: int = 0) Tuple[Transaction, str][source]¶
Prepare a new transaction.
- Parameters:
amount – Amount to send.
to_address – Destination DAG address.
from_address – Source DAG address.
last_ref – Dictionary with keys: ordinal, hash.
fee – Transaction fee.
- Returns:
TransactionV2 object, sha512hash, rle.
- static sign(private_key: str, msg: str) str[source]¶
Create transaction signature using the cryptography library.
- Parameters:
private_key – Private key in hex format.
msg – Transaction message (string).
- Returns:
Canonical DER signature in hex.
- static validate_address(address: str) bool[source]¶
Returns True if DAG address is valid, False if invalid.
- Parameters:
address – DAG address.
- Returns:
Boolean value.
- static validate_mnemonic(phrase: str) bool[source]¶
Returns True is phrase is valid, False if invalid.
- Parameters:
phrase – String of words (default: 12).
- Returns:
Boolean value.
- static verify(public_key: str, msg: str, signature: str) bool[source]¶
Verify is the signature is valid.
- Parameters:
public_key
msg – Hex format
signature
- Returns:
True or False
- verify_data(public_key: str, encoded_msg: str, signature: str)[source]¶
Verify a signature using the cryptography library.
- Parameters:
public_key – Public key in hex format (64-byte uncompressed, no 0x04 prefix).
encoded_msg – Original message string to verify.
signature – Canonical DER signature in hex.
- Returns:
True if valid, False otherwise.
pypergraph.keystore.kryo module¶
- class pypergraph.keystore.kryo.Kryo[source]¶
Bases:
object- serialize(msg: str, set_references: bool = True) str[source]¶
Serialize a message using a custom kryo-like serialization method. Used after encoding the message to sign.
- Parameters:
msg – The string message to serialize.
set_references – Whether to include references in the prefix.
- Returns:
The serialized message as a hexadecimal string.
pypergraph.keystore.v3_keystore module¶
- class pypergraph.keystore.v3_keystore.CryptoStruct[source]¶
Bases:
TypedDict- cipher: str¶
- cipherparams: CipherParams¶
- ciphertext: str¶
- kdf: str¶
- kdfparams: KDFParamsPhrase¶
- mac: str¶
- class pypergraph.keystore.v3_keystore.KDFParamsPhrase[source]¶
Bases:
TypedDict- c: int¶
- dklen: int¶
- prf: str¶
- salt: str¶
- class pypergraph.keystore.v3_keystore.V3Keystore[source]¶
Bases:
TypedDict- crypto: CryptoStruct¶
- id: str¶
- meta: NotRequired[str]¶
- version: int¶
- class pypergraph.keystore.v3_keystore.V3KeystoreCrypto[source]¶
Bases:
object- async static decrypt_phrase(keystore: V3Keystore, password: str) str[source]¶
- async static encrypt_phrase(phrase: str, password: str) V3Keystore[source]¶
- async pypergraph.keystore.v3_keystore.pbkdf2_async(passphrase: bytes, salt: bytes, iterations: int, keylen: int, digest: str) bytes[source]¶
- pypergraph.keystore.v3_keystore.type_check_jphrase(keystore: V3Keystore) bool[source]¶
Module contents¶
- class pypergraph.keystore.KeyStore[source]¶
Bases:
objectMethods dealing with keys.
- DATA_SIGN_PREFIX = '\x19Constellation Signed Data:\n'¶
- PERSONAL_SIGN_PREFIX = '\x19Constellation Signed Message:\n'¶
- data_sign(private_key, msg: dict, prefix: bool | str = True, encoding: Literal['base64'] | Callable[[dict], str] | None = None) Tuple[str, str][source]¶
Encode message according to serializeUpdate on your template module l1.
- param private_key:
- param msg:
Dictionary (the content of ‘value’ in a SignedTransaction).
- param prefix:
Enable or disable the default prefix ‘Constellation Signed Data:
- ‘ to the encoded msg or inject custom string.
- param encoding:
Can be None (default), ‘base64’ or a custom encoding function.
- return:
signature, transaction hash.
- async static decrypt_phrase(keystore: V3Keystore, password: str) str[source]¶
Can be used to decrypt the phrase using password.
- Parameters:
keystore
password
- Returns:
- static derive_account_from_master_key(master_key: BIP32Key, index: int) str[source]¶
Derive HD private key from master key.
- Parameters:
master_key
index
- Returns:
- encode_data(msg: dict, prefix: bool | str = True, encoding: Literal['base64'] | Callable[[dict], str] | None = None) str[source]¶
Encode custom data transaction for signing or signature verification.
- param msg:
Dictionary (the content of ‘value’ in a SignedTransaction).
- param prefix:
Enable or disable the default prefix ‘Constellation Signed Data:
- ‘ to the encoded msg.
- param encoding:
Can be None (default), ‘base64’ or a custom encoding function.
- return:
Encoded data transaction.
- async static encrypt_phrase(phrase: str, password: str) V3Keystore[source]¶
Can be used to encrypt the phrase using password.
- Parameters:
phrase
password
- Returns:
- encrypt_private_key(password: str, private_key: str | None = None) Dict[str, Any][source]¶
Can be stored (written to disk) and transferred.
- Parameters:
private_key
password
- Returns:
Dictionary, use json.dumps()
- static get_dag_address_from_public_key(public_key: str) str[source]¶
- Parameters:
public_key – The private key as a hexadecimal string.
- Returns:
The DAG address corresponding to the public key (node ID).
- static get_master_key_from_mnemonic(phrase: str, derivation_path: str = "m/44'/1137'/0'/0")[source]¶
Master key can be used to derive HD keys.
- Parameters:
phrase
derivation_path
- Returns:
- static get_private_key_from_mnemonic(phrase: str, derivation_path="m/44'/1137'/0'/0") str[source]¶
Get private key from phrase. Returns the first account.
- Parameters:
phrase
derivation_path
- Returns:
Private key as hexadecimal string
- static get_public_key_from_private(private_key: str) str[source]¶
- Parameters:
private_key
- Returns:
Public key (Node ID)
- static prepare_tx(amount: int, to_address: str, from_address: str, last_ref: TransactionReference, fee: int = 0) Tuple[Transaction, str][source]¶
Prepare a new transaction.
- Parameters:
amount – Amount to send.
to_address – Destination DAG address.
from_address – Source DAG address.
last_ref – Dictionary with keys: ordinal, hash.
fee – Transaction fee.
- Returns:
TransactionV2 object, sha512hash, rle.
- static sign(private_key: str, msg: str) str[source]¶
Create transaction signature using the cryptography library.
- Parameters:
private_key – Private key in hex format.
msg – Transaction message (string).
- Returns:
Canonical DER signature in hex.
- static validate_address(address: str) bool[source]¶
Returns True if DAG address is valid, False if invalid.
- Parameters:
address – DAG address.
- Returns:
Boolean value.
- static validate_mnemonic(phrase: str) bool[source]¶
Returns True is phrase is valid, False if invalid.
- Parameters:
phrase – String of words (default: 12).
- Returns:
Boolean value.
- static verify(public_key: str, msg: str, signature: str) bool[source]¶
Verify is the signature is valid.
- Parameters:
public_key
msg – Hex format
signature
- Returns:
True or False
- verify_data(public_key: str, encoded_msg: str, signature: str)[source]¶
Verify a signature using the cryptography library.
- Parameters:
public_key – Public key in hex format (64-byte uncompressed, no 0x04 prefix).
encoded_msg – Original message string to verify.
signature – Canonical DER signature in hex.
- Returns:
True if valid, False otherwise.