All repositories specified below contain smart contracts that implement confidentiality features using the COTI V2 protocol. The contracts provide examples for various use cases, such as Non-Fungible Tokens (NFTs), ERC20 tokens, Auction, and Identity management.
These contracts demonstrate how to leverage the confidentiality features of the COTI V2 protocol to enhance privacy and security in decentralized applications. The contracts are of Solidity and can be compiled and deployed using popular development tools like Hardhat and Foundry (Work in progress).
Docs | Devnet Explorer | Discord | Faucet
Interact with the network using any of the following:
The following contracts are available in each of the packages:
Contract | python sdk | hardhat sdk | typescript sdk | Contract Description | |
---|---|---|---|---|---|
AccountOnboard |
deployment | ✅ * | ✅ | ❌ | Onboard a EOA account - During onboard network creates AES unique for that EOA which is used for decrypting values sent back from the network |
AccountOnboard |
execution | âś… | âś… | âś… | " |
ERC20Example |
deployment | ✅ | ✅ | ❌ | Confidential ERC20 - deploy and transfer encrypted amount of funds |
ERC20Example |
execution | âś… | âś… | âś… | " |
NFTExample |
deployment | ❌ | ✅ | ❌ | Confidential NFT example - saving encrypted data |
NFTExample |
execution | ❌ | ✅ | ❌ | " |
ConfidentialAuction |
deployment | ❌ | ✅ | ❌ | Confidential auction - encrypted bid amount |
ConfidentialAuction |
execution | ❌ | ✅ | ❌ | " |
ConfidentialIdentityRegistry |
deployment | ❌ | ✅ | ❌ | Confidential Identity Registry - Encrypted identity data |
ConfidentialIdentityRegistry |
execution | ❌ | ✅ | ❌ | " |
DataOnChain |
deployment | ✅ | ❌ | ❌ | Basic encryption and decryption - Good place to start explorining network capabilties |
DataOnChain |
execution | ✅ | ❌ | ✅ | " |
Precompile |
deployment | ✅ | ✅ | ❌ | Thorough examples of the precompile functionality |
Precompile |
execution | ✅ | ✅ | ❌ | " |
(*) no deployment needed (system contract)
Note
Due to the nature of ongoing development, future version might break existing functionality
🤖 To request devnet/testnet funds use our faucet
Note
Please refer to the latest tags to find the most stable version to use. All tagged versions are available to install via npmjs
The COTI Typescript SDK is composed of two main components:
-
The
crypto_utils.ts
: used for cryptographic operations. -
The
ether_utils.ts
: used for ethers related operations -
Typescript classes to interact with the COTI network. These are located in the src/account directory. The following are provided:
-
confidential-account.ts
: designed to handle confidential data by providing methods for encryption and decryption, as well as onboarding new wallets. It utilizes cryptographic functions to ensure the security of data on the COTI network. -
onboard_contract.ts
: interact with the onboarding smart contract. The address and ABI allow a web3-enabled application to connect to the contract, listen for events, and call theOnboardAccount
function to onboard new accounts. -
onboard.ts
: facilitates the onboarding of new users by generating cryptographic keys, signing data, and interacting with a blockchain smart contract. Theonboard
function automates the entire process, ensuring secure onboarding and key management.
This TypeScript library, crypto_utils.ts
, provides cryptographic functions to interact with the COTI network. Below is
an overview of its components and functions:
crypto
: Node.js built-in module for cryptographic operations.ethers
: Ethereum library for various utilities, includingsolidityPackedKeccak256
,SigningKey
,getBytes
, andBaseWallet
.
block_size
: AES block size in bytes (16).hexBase
: Base for hexadecimal representation (16).
Encrypts the given plaintext using AES in ECB mode with the provided key.
- Parameters:
key
: 128-bit (16 bytes) key for AES encryption.plaintext
: Data to be encrypted (must be 128 bits or smaller).
- Returns:
ciphertext
: Encrypted data.r
: Random value used during encryption.
Decrypts the given ciphertext using AES in ECB mode with the provided key and random value.
- Parameters:
key
: 128-bit (16 bytes) key for AES decryption.r
: Random value used during encryption.ciphertext
: Encrypted data to be decrypted.
- Returns:
plaintext
: Decrypted data.
Generates a random 128-bit AES key.
Returns:
key
: The generated 128-bit AES key.
Generates a new RSA key pair.
- Returns:
publicKey
: RSA public key in DER format.privateKey
: RSA private key in DER format.
Decrypts the given ciphertext using RSA-OAEP with the provided private key.
- Parameters:
privateKey
: RSA private key in PEM format.ciphertext
: Data to be decrypted.
- Returns:
- Decrypted data.
Signs the given message using the provided private key.
- Parameters:
message
: Message to be signed.privateKey
: Signer's private key.
- Returns:
- Signature as a concatenation of
r
,s
, andv
values.
- Signature as a concatenation of
2. signInputText(wallet: BaseWallet, userKey: string, contractAddress: string , functionSelector: string, ct: Buffer)
Signs the given message using the provided private key.
- Parameters:
wallet
: an ether wallet to sign the ether transaction.privateKey
: Signer's private key.contractAddress
: the contract address.functionSelector
: the function signature.ct
: The ciphertext.
- Returns:
signature
: The generated signature.
3.buildInputText(plaintext: bigint, sender: { wallet: BaseWallet; userKey: string }, contractAddress: string, functionSelector: string)
Builds input text by encrypting the plaintext and signing it. Parameters:
plaintext
: The plaintext message.sender
: The sender's wallet and userKey.contractAddress
: The contract address.functionSelector
: The function signature.
Returns:
intCipherText
: The integer representation of the ciphertext.signature
: The generated signature.
4.buildStringInputText((plaintext: string, sender: { wallet: BaseWallet; userKey: string }, contractAddress: string, functionSelector: string)
Builds input text by encrypting the plaintext and signing it. Parameters:
plaintext
: The plaintext string message.sender
: The sender's wallet and userKey.contractAddress
: The contract address.functionSelector
: The function signature.
Returns:
intCipherText
: The integer representation of the ciphertext.signature
: The generated signature.
Decrypts a value stored in a contract using a user key.
Parameters:
ciphertext
: The value to be decrypted.userKey
: The user's AES key.
Returns:
result
: The decrypted value.
Decrypts a value stored in a contract using a user key.
Parameters:
ciphertext
: The value to be decrypted.userKey
: The user's AES key.
Returns:
result
: The decrypted value.
This TypeScript library, ethers_utils.ts
, provides ethers functionality to interact with the COTI-v2 network. Below is
an overview of its components and functions:
Prints the network details of the provider instance.
Parameters:
provider
: An instance of ethers provider.
Prints the account details of the default account in the Web3 instance.
Parameters:
provider
: An instance of ethers provider.address
: an Ethereum EOA account.
Retrieves the native balance of an address in wei.
Parameters:
provider
: An instance of ethers provider.address
: The address to check the balance of (default is the default account).
Returns:
result
: The address balance in wei.
Initializes the ethers RPC provider instance with the given node address.
Parameters:
rpcUrl
: The RPC address of the COTI node.
Returns:
provider
: The initialized Ether JsonRpcProvider instance.
Validates and returns the checksum address for a given address.
Parameters:
address
: The address to be validated.
Returns:
result
: A map withvalid
(boolean) andsafe
(checksum address).
Retrieves the latest block from the COTI network.
Parameters:
provider
: An instance of ethers provider.
Returns:
latestBlock
: The latest block object.
Retrieves the nonce for the default account.
Parameters:
provider
: An instance of ethers provider.address
: The address to check the balance of (default is the default account).
Returns:
nonce
: The nonce for the default account.
Checks if an address is valid.
Parameters:
address
: The address to be validated.
Returns:
valid
: Boolean indicating if the address is valid.
Generates an externally owned account (EOA) from a private key.
Parameters:
accountPrivateKey
: The private key of the account.
Returns:
eoa
: The generated EOA.
10. transferNative(provider: Provider, wallet: Wallet, recipientAddress: string, amountToTransferInWei: BigInt, nativeGasUnit: number)
Transfers native cryptocurrency from the default account to a recipient address.
Parameters:
provider
: An instance of ethers provider.wallet
: an ether wallet to sign the ether transaction.recipientAddress
: The address of the recipient.amountToTransferInWei
: The amount of Ether to transfer.nativeGasUnit
: The gas limit for the transaction.
Returns:
tx_receipt
: The transaction receipt.
Validates the gas estimation for a transaction.
Parameters:
provider
: An instance of ethers provider.tx
: The transaction object.
Checks if the provided gas units are sufficient for the transaction.
Parameters:
provider
: An instance of ethers provider.tx
: The transaction object.
Returns:
valid
: Boolean indicating if the gas units are sufficient.gas_estimate
: The estimated gas units.
Checks if the Web3 instance is connected.
Parameters:
provider
: An instance of ethers provider.
Returns:
connected
: Boolean indicating if Web3 is connected.
Retrieves the native balance of an address in Ether.
Parameters:
provider
: An instance of ethers provider.address
: The address to check the balance of (default is the default account).
Returns:
result
: The address balance in Ether.