npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@coti-io/coti-sdk-typescript

v0.6.6

Published

All repositories specified below contain smart contracts that implement confidentiality features using the COTI protocol. The contracts provide examples for various use cases, such as Non-Fungible Tokens (NFTs), ERC20 tokens, Auction, and Identity managem

Downloads

160

Readme

COTI Privacy Preserving L2 | SDKs and Examples

All repositories specified below contain smart contracts that implement confidentiality features using the COTI 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 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).

Important Links:

Docs | Devnet Explorer | Discord | Faucet

Interact with the network using any of the following:

  1. Python SDK | Python SDK Examples
  2. Typescript SDK | Typescript SDK Examples
  3. Hardhat Dev Environment

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

Faucet

🤖 To request devnet/testnet funds use our faucet

COTI Typescript SDK

[!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 mainly crypto_utils.ts: used for cryptographic operations.

(Ethers methods and mandatory wallet management operations, previously ethers_utils.ts, moved to coti-ethers)

CRYPTO Utilities (crypto_utils.ts)

This TypeScript library 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.

Installation

Ensure you have Node.js and npm installed. Then, install the necessary dependencies:

npm install node-forge ethers

Functions

encrypt(key: Uint8Array, plaintext: Uint8Array): { ciphertext: Uint8Array; r: Uint8Array }

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.

decrypt(key: Uint8Array, r: Uint8Array, ciphertext: Uint8Array): Uint8Array

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.

generateRSAKeyPair(): { publicKey: Uint8Array; privateKey: Uint8Array }

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).

decryptRSA(privateKey: Uint8Array, ciphertext: string): string

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.

sign(message: string, privateKey: string): Uint8Array

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 containing r, s, and v values.

signInputText(sender, contractAddress, functionSelector, ct: bigint): Uint8Array

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.

buildInputText(plaintext: bigint, sender, contractAddress, functionSelector): itUint

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.

buildStringInputText(plaintext: string, sender, contractAddress, functionSelector): itString

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.

decryptUint(ciphertext: ctUint, userKey: string): bigint

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.

decryptString(ciphertext: { value: bigint[] }, userKey: string): string

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.

generateRandomAesKeySizeNumber(): string

Generates a random 128-bit AES key.

  • Returns: A string containing the random bytes.

Utility Functions

  • encodeString(str: string): Uint8Array: Converts a string to a Uint8Array encoded with the hexadecimal representation of each character.
  • encodeKey(userKey: string): Uint8Array: Encodes a user key (hex string) to a Uint8Array.
  • encodeUint(plaintext: bigint): Uint8Array: Converts a bigint to a Uint8Array.
  • decodeUint(plaintextBytes: Uint8Array): bigint: Converts a Uint8Array to a bigint.
  • encryptNumber(r: string | Uint8Array, key: Uint8Array): Uint8Array: Encrypts a random value r using AES in ECB mode.

Constants

  • BLOCK_SIZE: AES block size in bytes (16).
  • HEX_BASE: Base used for hexadecimal conversion (16).
  • EIGHT_BYTES: Constant representing 8 bytes (used for processing data in chunks).

To report issues, please create a github issue