duniterpy.key package¶
Submodules¶
duniterpy.key.ascii_armor module¶
-
class
duniterpy.key.ascii_armor.AsciiArmor¶ Bases:
objectClass to handle writing and parsing of ascii armor messages
-
static
create(message: str, pubkey: Union[str, NoneType] = None, signing_keys: Union[typing.List[duniterpy.key.signing_key.SigningKey], NoneType] = None, message_comment: Union[str, NoneType] = None, signatures_comment: Union[str, NoneType] = None) → str¶ Encrypt a message in ascii armor format, optionally signing it
Parameters: - message – Utf-8 message
- pubkey – Public key of recipient for encryption
- signing_keys – Optional list of SigningKey instances
- message_comment – Optional message comment field
- signatures_comment – Optional signatures comment field
Returns:
-
static
parse(ascii_armor_message: str, signing_key: Union[duniterpy.key.signing_key.SigningKey, NoneType] = None, sender_pubkeys: Union[typing.List[str], NoneType] = None) → dict¶ Return a dict with parsed content (decrypted message, signature validation)
{ 'message': { 'fields': {}, 'content': str, }, 'signatures': [ {'pubkey': str, 'valid': bool, fields: {}} ] }
Parameters: - ascii_armor_message – The Ascii Armor Message Block including BEGIN and END headers
- signing_key – Optional Libnacl SigningKey instance to decrypt message
- sender_pubkeys – Optional sender’s public keys list to verify signatures
Raises: - libnacl.CryptError – Raise an exception if keypair fail to decrypt the message
- MissingSigningKeyException – Raise an exception if no keypair given for encrypted message
Returns:
-
static
-
exception
duniterpy.key.ascii_armor.MissingPublickeyAndSigningKeyException¶ Bases:
ExceptionRaise when the message created is not encrypted and not signed…
-
exception
duniterpy.key.ascii_armor.ParserMissingPublicKeysException¶ Bases:
ExceptionRaise when there is at least one signature but no public keys are provided
-
exception
duniterpy.key.ascii_armor.ParserMissingSigningKeyException¶ Bases:
ExceptionRaise when the message is encrypted but no SigningKey instance is provided
duniterpy.key.base58 module¶
duniterpy.key.constants module¶
duniterpy.key.encryption_key module¶
duniter public and private keys
@author: inso
-
class
duniterpy.key.encryption_key.PublicKey(pubkey: str)¶ Bases:
libnacl.public.PublicKey-
base58() → str¶ Return a base58 encoded string of the public key
-
encrypt_seal(data: Union[str, bytes]) → bytes¶ Encrypt data with a curve25519 version of the ed25519 public key
Parameters: data – Bytes data to encrypt
-
-
class
duniterpy.key.encryption_key.SecretKey(salt: Union[str, bytes], password: Union[str, bytes], scrypt_params: Union[duniterpy.key.scrypt_params.ScryptParams, NoneType] = None)¶ Bases:
libnacl.public.SecretKeyRaw Public Key Encryption Class
-
decrypt(pubkey: str, nonce: Union[str, bytes], text: str) → str¶ Decrypt encrypted message text with recipient public key and the unique nonce used by the sender.
Parameters: - pubkey – Public key of the recipient
- nonce – Unique nonce used by the sender
- text – Encrypted message
Returns:
-
encrypt(pubkey: str, nonce: Union[str, bytes], text: Union[str, bytes]) → str¶ Encrypt message text with the public key of the recipient and a nonce
The nonce must be a 24 character string (you can use libnacl.utils.rand_nonce() to get one) and unique for each encrypted message.
Return base58 encoded encrypted message
Parameters: - pubkey – Base58 encoded public key of the recipient
- nonce – Unique nonce
- text – Message to encrypt
Returns:
-
duniterpy.key.scrypt_params module¶
-
class
duniterpy.key.scrypt_params.ScryptParams(n: Union[int, NoneType] = 4096, r: Union[int, NoneType] = 16, p: Union[int, NoneType] = 1, seed_length: Union[int, NoneType] = 32)¶ Bases:
objectClass to simplify handling of scrypt parameters
duniterpy.key.signing_key module¶
duniter public and private keys
@author: inso
-
class
duniterpy.key.signing_key.SigningKey(seed: bytes)¶ Bases:
libnacl.sign.Signer-
decrypt_seal(data: bytes) → bytes¶ Decrypt bytes data with a curve25519 version of the ed25519 key pair
Parameters: data – Encrypted data Returns:
-
classmethod
from_credentials(salt: Union[str, bytes], password: Union[str, bytes], scrypt_params: Union[duniterpy.key.scrypt_params.ScryptParams, NoneType] = None) → SigningKeyType¶ Create a SigningKey object from credentials
Parameters: - salt – Secret salt passphrase credential
- password – Secret password credential
- scrypt_params – ScryptParams instance
-
static
from_ewif_file(path: str, password: str) → SigningKeyType¶ Return SigningKey instance from Duniter EWIF file
Parameters: - path – Path to EWIF file
- password – Password of the encrypted seed
-
classmethod
from_ewif_hex(ewif_hex: str, password: str) → SigningKeyType¶ Return SigningKey instance from Duniter EWIF in hexadecimal format
Parameters: - ewif_hex – EWIF string in hexadecimal format
- password – Password of the encrypted seed
-
static
from_private_key(path: str) → SigningKeyType¶ Read authentication file Add public key attribute
Parameters: path – Authentication file path
-
classmethod
from_pubsec_file(path: str) → SigningKeyType¶ Return SigningKey instance from Duniter WIF file
Parameters: path – Path to WIF file
-
classmethod
from_seedhex(seedhex: str) → SigningKeyType¶ Return SigningKey instance from Seedhex
Parameters: seedhex (str) – Hexadecimal seed string
-
static
from_seedhex_file(path: str) → SigningKeyType¶ Return SigningKey instance from Seedhex file
Parameters: path (str) – Hexadecimal seed file path
-
static
from_wif_file(path: str) → SigningKeyType¶ Return SigningKey instance from Duniter WIF file
Parameters: path – Path to WIF file
-
classmethod
from_wif_hex(wif_hex: str) → SigningKeyType¶ Return SigningKey instance from Duniter WIF in hexadecimal format
Parameters: wif_hex – WIF string in hexadecimal format
-
static
from_wif_or_ewif_file(path: str, password: Union[str, NoneType] = None) → SigningKeyType¶ Return SigningKey instance from Duniter WIF or EWIF file
Parameters: - path – Path to WIF of EWIF file
- password – Password needed for EWIF file
-
static
from_wif_or_ewif_hex(wif_hex: str, password: Union[str, NoneType] = None) → SigningKeyType¶ Return SigningKey instance from Duniter WIF or EWIF in hexadecimal format
Parameters: - wif_hex – WIF or EWIF string in hexadecimal format
- password – Password of EWIF encrypted seed
-
save_ewif_file(path: str, password: str) → None¶ Save an Encrypted Wallet Import Format file (WIF v2)
Parameters: - path – Path to file
- password –
-
save_private_key(path: str) → None¶ Save authentication file
Parameters: path – Authentication file path
-
save_pubsec_file(path: str) → None¶ Save a Duniter PubSec file (PubSec) v1
Parameters: path – Path to file
-
save_seedhex_file(path: str) → None¶ Save hexadecimal seed file from seed
Parameters: path – Authentication file path
-
save_wif_file(path: str) → None¶ Save a Wallet Import Format file (WIF) v1
Parameters: path – Path to file
-
duniterpy.key.verifying_key module¶
duniter public and private keys
@author: inso
-
class
duniterpy.key.verifying_key.VerifyingKey(pubkey: str)¶ Bases:
libnacl.sign.VerifierClass to verify documents
-
get_verified_data(data: bytes) → bytes¶ Check specified signed data signature and return data
Raise exception if signature is not valid
Parameters: data – Data + signature Returns:
-
verify_document(document: duniterpy.documents.document.Document) → bool¶ Check specified document :param duniterpy.documents.Document document: :return:
-
verify_ws2p_head(head: Any) → bool¶ Check specified document :param Any head: :return:
-