TypeScript SDK
The COTI Typescript 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.
Features
AES encryption with ECB mode for data of fixed block sizes.
RSA key pair generation, encryption, and decryption using RSA-OAEP with SHA-256.
Signing of Ethereum transactions using the
ethers
library's signing mechanisms.Utilities for encoding/decoding, padding, and cryptographic data manipulation.
Clone, Build & Test
Full instructions for building and testing the package locally are available in the coti-sdk-typescript 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-typescript-examples repository for code examples.
Functions
Encrypts a given plaintext using the provided AES key. The plaintext is XORed with an encrypted random value.
Parameters:
key
: The AES encryption key (16 bytes).plaintext
: The data to be encrypted (must be 16 bytes or smaller).
Returns: An object containing:
ciphertext
: The encrypted data.r
: The random value used in the encryption process.
Decrypts a ciphertext using the provided AES key and random value r
.
Parameters:
key
: The AES encryption key (16 bytes).r
: The random value used during encryption (16 bytes).ciphertext
: The encrypted data (16 bytes).
Returns: The decrypted plaintext.
Generates a new RSA key pair (2048 bits) and returns the keys in DER format.
Returns: An object containing:
publicKey
: The RSA public key (DER-encoded).privateKey
: The RSA private key (DER-encoded).
Decrypts an RSA-encrypted ciphertext using the provided private key.
Parameters:
privateKey
: The RSA private key (DER-encoded).ciphertext
: The encrypted ciphertext as a hex string.
Returns: The decrypted message as a string.
Signs a message using the provided Ethereum private key.
Parameters:
message
: The message to be signed.privateKey
: The Ethereum private key.
Returns: A signature as a
Uint8Array
containingr
,s
, andv
values.
Generates a signed message hash for Ethereum contract interactions.
Parameters:
sender
: The sender's information containing their wallet and user key.contractAddress
: The Ethereum contract address.functionSelector
: The function selector (bytes4) for the contract function.ct
: The ciphertext (big integer).
Returns: A signature for the provided message.
Encrypts a plaintext (up to 64 bits) and generates a signed transaction payload.
Parameters:
plaintext
: The data to be encrypted (must be smaller than 64 bits).sender
: The sender's information containing their wallet and user key.contractAddress
: The Ethereum contract address.functionSelector
: The function selector for the contract function.
Returns: An
itUint
object containing the encrypted ciphertext and signature.
Encrypts a plaintext string and generates a signed transaction payload.
Parameters:
plaintext
: The data to be encrypted (string).sender
: The sender's information containing their wallet and user key.contractAddress
: The Ethereum contract address.functionSelector
: The function selector for the contract function.
Returns: An
itString
object containing the encrypted ciphertext and signature.
Decrypts an AES-encrypted ciphertext and returns the original plaintext as a bigint
.
Parameters:
ciphertext
: The encrypted ciphertext.userKey
: The user key for AES decryption.
Returns: The decrypted plaintext as a
bigint
.
Decrypts an AES-encrypted ciphertext representing a string.
Parameters:
ciphertext
: An object containing the encrypted ciphertext as a list of bigints.userKey
: The user key for AES decryption.
Returns: The decrypted plaintext as a string.
Generates a random 128-bit AES key.
Returns: A string containing the random bytes.
Last updated