Python SDK
The COTI Python SDK provides a set of encryption, decryption, and cryptographic utilities, including RSA and AES encryption, message signing, and key handling functions. The utilities are primarily designed to work with cryptographic operations for secure communication and message signing, particularly within Ethereum smart contracts or similar environments.
Clone, Build & Test
Full instructions for building and testing the package locally are available in the coti-sdk-python GitHub repository
Installation
SDK versions < 1.0.0 are for use with the Devnet, versions >= 1.0.0 are for use with the Testnet
Usage
See the coti-sdk-python-examples repository for code examples.
Modules
Crypto
Encrypts a 128-bit plaintext
using the provided 128-bit AES key
and ECB mode.
Parameters:
key (bytes)
: 128-bit AES key (16 bytes).plaintext (bytes)
: 128-bit or smaller plaintext to encrypt.
Returns:
ciphertext (bytes)
: The encrypted text.r (bytes)
: A random value used during encryption.
Decrypts the ciphertext
using the provided 128-bit AES key
and the random value r
.
Parameters:
key (bytes)
: 128-bit AES key.r (bytes)
: Random value used during encryption.ciphertext (bytes)
: Encrypted text to decrypt.
Returns:
plaintext (bytes)
: The decrypted original message.
Generates a random 128-bit AES key.
Returns:
key (bytes)
: Randomly generated 128-bit key (16 bytes).
Signs an input message composed of multiple parts, including sender address, contract address, function selector, and ciphertext.
Parameters:
sender (bytes)
: Sender address.addr (bytes)
: Contract address.function_selector (str)
: Ethereum function selector (in hex).ct (bytes)
: Ciphertext (concatenated).key (bytes)
: Private key for signing.
Returns:
signature (bytes)
: Digital signature of the message.
Signs a message
using the provided key
(Ethereum-style private key).
Parameters:
message (bytes)
: Message to sign.key (bytes)
: Private key to use for signing.
Returns:
signature (bytes)
: The generated signature.
Encrypts a plaintext integer and signs the resulting ciphertext along with other parameters.
Parameters:
plaintext (int)
: Integer to encrypt.user_aes_key (bytes)
: AES key for encryption.sender (object)
: Ethereum-like sender object (withaddress
attribute).contract (object)
: Ethereum-like contract object (withaddress
attribute).function_selector (str)
: Function selector (in hex).signing_key (bytes)
: Signing key for signature.
Returns:
dict
: Contains theciphertext
andsignature
.
Encrypts and signs string-based input data, breaking it into 8-byte chunks.
Parameters:
plaintext (str)
: String to encrypt.user_aes_key (bytes)
: AES key for encryption.sender (object)
: Ethereum-like sender object.contract (object)
: Ethereum-like contract object.function_selector (str)
: Function selector (in hex).signing_key (bytes)
: Signing key for signature.
Returns:
dict
: Contains theciphertext
andsignature
.
Decrypts a ciphertext into an unsigned integer using AES.
Parameters:
ciphertext (CtUint)
: Ciphertext to decrypt (in integer format).user_key (bytes)
: AES key to use for decryption.
Returns:
int
: The decrypted integer.
Decrypts a ciphertext back into a string, handling multiple formats of ciphertext.
Parameters:
ciphertext (CtString)
: Ciphertext to decrypt, can be in event or state variable format.user_key (bytes)
: AES key to use for decryption.
Returns:
str
: The decrypted string.
Generates an RSA key pair for encryption and decryption.
Returns:
private_key_bytes (bytes)
: Serialized private key.public_key_bytes (bytes)
: Serialized public key.
Decrypts a ciphertext using RSA and a provided private key.
Parameters:
private_key_bytes (bytes)
: Private key used for decryption.ciphertext (bytes)
: Ciphertext to decrypt.
Returns:
plaintext (bytes)
: Decrypted plaintext.
Last updated