Skip to main content

Soda SDK - Cryptographic functions for Soda Labs blockchain

Project description

Soda-sdk

This SDK provides functionalities for AES and RSA encryption schemes, ECDSA signature scheme and some functionalities used for working with sodalabs interface.

Table of Contents

Available functionalities

The SDK supports the following functionalities:

  • AES encryption scheme:

    • Generate AES key
    • Write AES key
    • Load AES key
    • Encrypt
    • Decrypt
  • RSA encryption scheme:

    • Generate RSA key pair
    • Encrypt
    • Decrypt
  • ECDSA signature scheme:

    • Generate ECDSA private key
    • Sign
  • Hash:

    • Keccak 256
  • Functionalities related to sodalabs InputText:

    • Sign InputText function

      This function gets:

      • sender address bytes
      • contract address bytes
      • hashed function signature bytes
      • ciphertext bytes
      • ECDSA private key bytes.

      It appends the addresses, signature and ciphertext and signs the appended string using the private key.

    • Verify IT (Available only in Golang) This function gets:

      • sender address bytes
      • contract address bytes
      • hashed function signature bytes
      • ciphertext bytes
      • signature

      It verify the signature against the received data

    • Prepare InputText function

      This function gets:

      • plaintext
      • AES key
      • sender address
      • contract address
      • function signature (as string in go and python case, or hashed in js case)
      • ECDSA private key.

      It encrypt the plaintext using the AES key to get the ciphertext, then sign the concatination of the addresses, hashed function signature and ciphertext using the ECDSA private key.

    • Get function signature

      This function get the function signature as a string and returned the keccak-256 value on the signature

Prerequisites

Python should be installed on your system.

Installation

pip install gcevm-sdk

Usage

In order to use the functionalities of python SDK, first import the modules from 'crypto' file. for example:

from soda_python_sdk import prepare_IT, decrypt

Below is an example function from the python test file that demonstrate using some of the SDK functionality. Lets break it down:

def test_prepareIT(self):
    # Create inputs for prepare_IT function
    plaintext = 100                                                     # plaintext 
    userKey = bytes.fromhex("b3c3fe73c1bb91862b166a29fe1d63e9")         # AES key
    sender = Account()                                                  # Sender account
    sender.address = "0xd67fe7792f18fbd663e29818334a050240887c28"
    contract = Account()                                                # Contract account
    contract.address = "0x69413851f025306dbe12c48ff2225016fc5bbe1b"
    func_sig = "test(bytes)"                                            # function signature as string
    signingKey = bytes.fromhex("3840f44be5805af188e9b42dda56eb99eefc88d7a6db751017ff16d0c5f8143e")  # ECDSA private key

    # Call prepare_IT function with the plaintext, AES key, sender and contract accounts, function signature and ECDSA private key
    ct, signature = prepare_IT(plaintext, userKey, sender, contract, func_sig, signingKey)
    # prepare_IT returns the ciphertext and the signature

    # Verify the signature
    sender_address_bytes = bytes.fromhex(sender.address[2:])     # Get the bytes of the accounts addresses
    contract_address_bytes = bytes.fromhex(contract.address[2:])
    func_hash = get_func_sig(func_sig)                           # Create the function signature
    # Create the signed message 
    message = sender_address_bytes + contract_address_bytes + func_hash + ctBytes
    pk = keys.PrivateKey(signingKey)
    signature = keys.Signature(signature)
    # Verify the signature against the message hash and the public key
    verified = signature.verify_msg(message, pk.public_key)
    self.assertEqual(verified, True)

    # Decrypt the ciphertext using the AES key and check the decrypted value against the original plaintext
    ctBytes = ct.to_bytes((ct.bit_length() + 7) // 8, 'big')
    
    # ctBytes is divided into two components: random and encrypted data. The decrypt function processes each component separately. 
    decrypted = decrypt(userKey, ctBytes[block_size:], ctBytes[:block_size])
    decrypted_integer = int.from_bytes(decrypted, 'big')
    self.assertEqual(plaintext, decrypted_integer)

This example uses the prepare_IT and decrypt functionalities of the python SDK. More examples can be found in the test.py file.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gcevm_sdk-0.0.4.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gcevm_sdk-0.0.4-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file gcevm_sdk-0.0.4.tar.gz.

File metadata

  • Download URL: gcevm_sdk-0.0.4.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.4

File hashes

Hashes for gcevm_sdk-0.0.4.tar.gz
Algorithm Hash digest
SHA256 15ad91fd816ed7a8fd718679e825d8fc4f20ba5de378b80a56ed28b9954daebc
MD5 aa35e8f941c6fa59b08c3f60dfc5244a
BLAKE2b-256 08806a9fbae08fecf3318afa3725d2a9b9341decf7cc3af9c0794c9b09d8ffb4

See more details on using hashes here.

File details

Details for the file gcevm_sdk-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: gcevm_sdk-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.4

File hashes

Hashes for gcevm_sdk-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b3bfb11e38852efd02c1a6e1ccfdf3b443750423eb52d550c52d5054e8afe7d9
MD5 706d9b1e782dc31041aacd9a779d7826
BLAKE2b-256 75c91518ed85e8df181fd197faf87db9cdb22cb32cc7e76317d74767fe14b442

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page