from cryptography.fernet import Fernet def encrypt_message(public_key, message): # Get the public key in bytes public_key_bytes = bytes.fromhex(public_key) # Generate a symmetric key symmetric_key = Fernet.generate_key() # Encrypt the message using the symmetric key f = Fernet(symmetric_key) encrypted_message = f.encrypt(message.encode()) # Encrypt the symmetric key using the public key rsa_key = RSA.import_key(public_key_bytes) cipher_rsa = PKCS1_OAEP.new(rsa_key) encrypted_key = cipher_rsa.encrypt(symmetric_key) return encrypted_key, encrypted_message

import ecdsa # Generate a private key private_key = ecdsa.SigningKey.generate(curve=ecdsa.SECP256k1) # Get the public key public_key = private_key.get_verifying_key() # Encode the keys to hexadecimal format private_key_hex = private_key.to_string().hex() public_key_hex = public_key.to_string().hex() print(f'Private key: {private_key_hex}') print(f'Public key: {public_key_hex}') from cryptography.fernet import Fernet def encrypt_message(public_key, message): # Get the public key in bytes public_key_bytes = bytes.fromhex(public_key) # Generate a symmetric key symmetric_key = Fernet.generate_key() # Encrypt the message using the symmetric key f = Fernet(symmetric_key) encrypted_message = f.encrypt(message.encode()) # Encrypt the symmetric key using the public key rsa_key = RSA.import_key(public_key_bytes) cipher_rsa = PKCS1_OAEP.new(rsa_key) encrypted_key = cipher_rsa.encrypt(symmetric_key) return encrypted_key, encrypted_message from cryptography.fernet import Fernet def encrypt_message(public_key, message): # Get the public key in bytes public_key_bytes = bytes.fromhex(public_key) # Generate a symmetric key symmetric_key = Fernet.generate_key() # Encrypt the message using the symmetric key f = Fernet(symmetric_key) encrypted_message = f.encrypt(message.encode()) # Encrypt the symmetric key using the public key rsa_key = RSA.import_key(public_key_bytes) cipher_rsa = PKCS1_OAEP.new(rsa_key) encrypted_key = cipher_rsa.encrypt(symmetric_key) return encrypted_key, encrypted_message

When I asked “Open AI”, could I use ,Maria DB,” as my data base for a Blockchain, this is what “Open AI, said”:

Siddharth Gangwar

Siddharth Gangwar

Apr 1, 2022

·

4 min read

·

Listen

LevelDB — Invented by Google and used by cryptocurrencies like Bitcoin (₿)

What is LevelDb?

LevelDB is a fast key-value storage library written at Google that provides an ordered mapping from string keys to string values. Apart from being open-source, it is written in C++ and was launched in 2011.

Moreover, LevelDB is an LSM-based key-value store that offers enhanced write throughput and reasonable read throughput. Essentially, LevelDB excels at random reads and writes.

How it is used by Bitcoin & Ethereum?

Before moving on that how does it uses LevelDB to store data, we first need to understand what are UTXO (unspent transaction output) in any cryptocurrency.

Let’s assume you receive 5 ₿ from your father, 3 ₿ from your mother and 2 ₿ from a shop keeper. You have 3 UTXO.

Bitcoin wallet balance = 5  + 3  + 2 

In total you had 10 ₿. Now, you went to purchase a gadget which was priced at 6.98 ₿. Since you had enough Bitcoins, you transferred 5 ₿ & 2 ₿ for the gadget.

Bitcoin wallet balance = 3 

Since, the remaining balance 0.02 ₿ was left. You get 0.01 ₿ back because 0.01 ₿ is deducted as the fee for the transaction. Now, you converted 3 UTOX to 2 UTOX.

Bitcoin wallet balance = 3  + 0.01 

In general, Bitcoin could be any number instead of fixed numbers as we have in any currency like dollars. The minimum value it should be is 1 Satoshi.

Note: 100 million Satoshis == 1 Bitcoin

Let’s look how does LevelDb comes in picture.

When ever a transaction occur, we all know that basically every cryptocurrency is a blocks of chain or it can be assumed as ledgers.

Bitcoin works on mechanism of Transaction ledgers.
Ethereum works on mechanism of Balance ledges.

Crypto blocks just contain the relevant information about the transaction such as:

  • Previous hash of the block.
  • Merkel tree root hash.
  • Nonce.
  • Spent transaction output hash.
  • Etc, depending upon cryptocurrencies.

There are four pieces of data that are maintained

  • blocks/blk*.dat
  • blocks/index/*
  • chainstate/*
  • blocks/rev*.dat

Among these lets discuss more about chainstate/* & blocks/index/*.

blocks/index/*: this is a LevelDB database that contains metadata about all known blocks, and where to find them on disk. Without this, finding a block would be very slow.

Chainstate/*: this is a LevelDB database with a compact representation of all currently UTXO’s and some metadata about the transactions they are from. The data here is necessary for validating new incoming blocks and transactions. It can theoretically be rebuilt from the block data, but this takes a rather long time. Without it, you could still theoretically do validation indeed, but it would mean a full scan through the blocks (398.37 GB as of 31 March, 2022) for every output being spent.

Why LevelDB?

The LevelDB’s are redundant in the sense that they can be rebuilt from the block data. But validation and other operations would become intolerably slow without them.

References

What is LevelDB and how does it work?

Databases form an important part of an application stack, after the server and client side parts of it have been…

dev.to

Bitcoin Core 0.11 (ch 2): Data Storage

This page describes how & where Bitcoin Core stores blockchain data. There are basically four pieces of data that are…

en.bitcoin.it

What is the database for?

Thanks for contributing an answer to Bitcoin Stack Exchange! Please be sure to answer the question. Provide details and…

bitcoin.stackexchange.com

LevelDB – Wikipedia

LevelDB is an open-source on-disk key-value store written by Google fellows Jeffrey Dean and Sanjay Ghemawat. Inspired…

en.wikipedia.org

GitHub – google/leveldb: LevelDB is a fast key-value storage library written at Google that…

LevelDB is a fast key-value storage library written at Google that provides an ordered mapping from string keys to…

github.com

Join Coinmonks Telegram Channel and Youtube Channel learn about crypto trading and investing

Also, Read

Cryptocurrency

Blockchain

Blockchain Technology

Database

Bitcoin

14

14

Sign up for Coinmonks

By Coinmonks

A newsletter that brings you day’s best crypto news, Technical analysis, Discount Offers, and MEMEs directly in your inbox, by CoinCodeCap.com Take a look.

Get this newsletter

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

More from Coinmonks

Follow

Coinmonks (http://coinmonks.io/) is a non-profit Crypto Educational Publication. Follow us on Twitter @coinmonks and Our other project —  https://coincodecap.com, Email  — gaurav@coincodecap.com

CoinMenorah

CoinMenorah

·Apr 1, 2022

Zilliqa grew 500% in the last week. Is it undervalued?

*Please note that this article is not financial advice. Layer 1 smart contract platform Zilliqa’s native token ZIL rose almost 500% in price, from $0.045 to a high of $0.22. The token has since retraced to $0.18. …

Bitcoin

7 min read

Zilliqa grew 500% in the last week. Is it undervalued?

Share your ideas with millions of readers.

Write on Medium


Hummingbird Finance & NestSwap

Hummingbird Finance & NestSwap

·Apr 1, 2022

Metalandz joins NestSwap to offer yield farming and a staking pool for holders

Long term partnership begins with Metalandz and Hummingbird Finance on their decentralized platform, NestSwap — Metalandz, what’s it all about? Metalandz is a play-to-earn gaming platform based on the BNB Chain. Their vision is to offer a deeply immersive platform in which players will create their own non-fungible tokens (NFTs) and rewarding their participation with our governance and utility token — METAZ by playing Poly Jungle.

Yield Farming

3 min read

Metalandz joins NestSwap to offer yield farming and a staking pool for holders

JKL Group

JKL Group

·Apr 1, 2022

March Overview

Your Monthly Brief into the World of Digital Assets — Article by Sixte C. Edited by Lesia M. Market Overview Open Interest Regulators Biden issues an Executive Order focused on cryptocurrencies European Union voted for a new regulatory framework on cryptocurrencies Swiss city, Lugano, will accept BTC, UST and LVGA as ‘de facto’ legal tender Financial institutions, DeFi, GameFi Why LUNA’s price rose 133% in two months…

Bitcoin

13 min read

March Overview

Crypto Conquest

Crypto Conquest

·Apr 1, 2022

Member-only

Prepare The Pitchforks: Harmful EU Crypto Regulations

LFG BTC plan | Market Update | EU Vote | NFT — Prepare the pitchforks; the battle for crypto never ends, and the community is preparing for a critical EU regulation vote that could shape the future of digital assets. In the meantime, the metaverse gets its first MetaUniversity, and is Do Kwon set to become the biggest bitcoin whale of all? …

Cryptocurrency

5 min read

Prepare The Pitchforks: Harmful EU Crypto Regulations

VeriDoc Global

VeriDoc Global

·Apr 1, 2022

VeriDoc Ledger: A Blockchain Fit for Government and Enterprise

VeriDoc Global is a patented verification protocol that can be integrated with any blockchain. The multichain solution currently leverages seven different blockchains. Each blockchain has its own unique strengths and weaknesses. VeriDoc Ledger is the seventh blockchain to be added to VeriDoc Global’s suite and was developed to fill the…

Verification

5 min read

VeriDoc Ledger: A Blockchain Fit for Government and Enterprise

Read more from Coinmonks

Recommended from Medium

Elizabeth Levine

Elizabeth Levine

Boys club: Fewer than 1 in 10 crypto investors is female (From Yahoo Finance by Rubina Ahmed-Haq)

Boosted Finance

Boosted Finance

🚀 Boosted Finance: Strategist Competition Kickoff

Adebimpe Adedigba

Adebimpe Adedigba

AMA RECAP WITH CASSAVA NETWORK

实验室

实验室

DeFi Watcher

Justin Hartzman

Justin Hartzman

Two Weird Things Have Happened Lately… Did You Notice?

Lydia Finance

Lydia Finance

OrcaDAO x Lydia Finance Partnership

ArgusNFT

ArgusNFT

ArgusNFT secures funding to advance adoption of Cardano NFTs

SHA256 Hash: 56caf99c3111eb785b5ccad64bdc7e1d087a6ba16919ffdefa1adc38c373c5b6

Leave a Reply

Your email address will not be published. Required fields are marked *