Skip to main content

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

Project description

Soda-sdk

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

Table of Contents

Available functionalities

The SDK support provide 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 soda-sdk

Usage

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

from crypto 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

soda_sdk-0.0.1.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

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

soda_sdk-0.0.1-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file soda_sdk-0.0.1.tar.gz.

File metadata

  • Download URL: soda_sdk-0.0.1.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.5

File hashes

Hashes for soda_sdk-0.0.1.tar.gz
Algorithm Hash digest
SHA256 6843e612662bfd7a179f4d7196dc5e621988b724f098888dcc45a15a29398dfd
MD5 a429207750856817590c55f8be77c749
BLAKE2b-256 ab2b9f24b8a9ff7b50e7d2fb6889ae1a097a7192b636f298d114208c14a2936e

See more details on using hashes here.

File details

Details for the file soda_sdk-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: soda_sdk-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.5

File hashes

Hashes for soda_sdk-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ebff6c1337ac47671bf5c0fc1edfee6d3b222d02d5f813745a9cdca592451a85
MD5 e4ea6a72847b91e357a51e1eb727eda9
BLAKE2b-256 d8a02c96cf48b2586cfca020d5180b2478794bc936d7223942b60a0a89804163

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