LevelDB & Crypto
2 hours, 28 minutes
Become a Master
This course and others like it are available as part of our Frontend Masters video subscription.
Watch Free Preview
Join Frontend Masters
Dive into cryptography fundamentals and LevelDB to build stronger, more secure applications! Code with James Halliday as you pair modern cryptography and the modular NoSQL databases of LevelDB to help you fortify your communications systems.
Published: September 13, 2017
Table of Contents
00:00:00 - 00:07:32
James Halliday introduces and sets up LevelDB, a key-value storage library written at Google that provides an ordered mapping from string keys to string values.
00:07:33 - 00:14:57
Methods and Lexicographically
After James reviews the methods that are available with LevelDB, he notes that LevelDB uses lexicographic sorting, which alphabetical order of string values based on the alphabetical order. J
00:14:58 - 00:18:45
With the LevelDB setup, James demonstrates how to organize keys for different situations such as a simple blog and creates queries against that data.
00:18:46 - 00:21:16
James introduces how to create multiple keys for each post to create a secondary index.
00:21:17 - 00:45:36
With the database set up, James reviews how to build a system to add new data into LevelDB. - https://github.com/substack/lexicographic-integer
00:45:37 - 00:47:10
Adding and Querying Data
James adds new posts with timestamps to the database. Then James examines different ways to query that data from the LevelDB database.
00:47:11 - 00:48:49
James introduces Subleveldown, which a library for LevelDB that creates nested sub-databases with unique namespaces; - https://github.com/mafintosh/subleveldown
00:48:50 - 00:53:24
James installs Level-Livefeed package that allows for one to subscribe to a live feed of changes to the database. - https://github.com/Raynos/level-livefeed
00:53:25 - 01:01:44
To use LevelDB in the browser, James switches from level package to include level-browserify. This change allows the use of the LevelUP code to be portable making it work with node and in the browser. - https://github.com/Level/level-browserify
01:01:45 - 01:07:53
After reviewing the best use cases for LevelDB, James creates a demo application with LevelDB, node, and IndexedDB.
01:07:54 - 01:09:22
Q&A: IndexedDB vs. LocalStorage
James takes questions from the students about IndexedDB and LocalStorage, browser support, and more.
01:09:23 - 01:11:41
James introduces hashes. While encryption is a two-step process used first to encrypt and then decrypt a message, hashing condenses a message into an irreversible fixed-length value or hash. - https://github.com/crypto-browserify/createHash
01:11:42 - 01:16:03
Approaches to Cryptography
James discusses approaches to cryptography including random number generators, symmetric ciphers, and asymmetric crypto. Cipher is a shared algorithm for performing encryption or decryption whereas asymmetric crypto uses public and private keys to encrypt and decrypt data. James also notes that is an important tool with cryptography is picking a robust random number generator. Finally, James warns against creating your encryption process. - https://en.wikipedia.org/wiki/Category:Cryptographic_attacks
01:16:04 - 01:27:49
Sodium and Chloride
James introduces Sodium, a library for encryption, decryption, signatures, and password hashing. Then James demonstrates how to setup Chloride, which is based on Sodium, and generate key pairs. - https://github.com/dominictarr/chloride
01:27:50 - 01:30:46
James discusses how to use Sodium cryptography with or without a signature, using a symmetric cipher, and using public key encryption.
01:30:47 - 01:33:47
James reviews secret-handshake library, which is used to keep both parties unaware of each other with mutually authenticating key agreement handshake. James takes questions from students. - https://github.com/auditdrivencrypto/secret-handshake
01:33:48 - 01:42:23
James reviews merkle DAGs, which is a directed acyclic graph whose objects are linked to each other (usually just by their hash), where the hash(object) includes all hash(linked_object).
01:42:24 - 01:50:33
Working with merkle DAGs
James demonstrates how to use merkle DAGs with node using shasum, which checks for SHA checksums.
01:50:34 - 02:00:23
Introducing Kappa Architecture
James introduces Kappa Architecture, where an immutable and append-only logs are used as the source of truth. To create these append-only logs, James notes that they are built hashes that are then trivial to replicate with concatenation.
02:00:24 - 02:05:38
James reviews hyperlog, which creates append-only merkle DAG log store. Hyperlog also can link to other documents by cryptographic hash and provides hooks for cryptographic signing and verification. Then James shows how to set up hyperlog. - https://github.com/mafintosh/hyperlog
02:05:39 - 02:07:09
Database Replication and Duplex Streams
James discusses how to synchronous two databases. James takes questions from students. - https://github.com/substack/dupsh
02:07:10 - 02:08:09
James reviews hyperlog-index, which builds materialized views on top of a hyperlog. - https://github.com/substack/hyperlog-index
02:08:10 - 02:09:40
Hyperkv and Hyperlog-sodium
James shows hyperkv, which provides a p2p key/value store as a materialized view over a hyperlog. Then James discusses hyperlog-sodium, which more easily configures hyperlog for cryptographic signing. - - https://github.com/substack/hyperkv - https://github.com/substack/hyperlog-sodium
02:09:41 - 02:16:36
Kappa Architecture Examples
James reviews several examples of kappa architecture: P2P social database; map database built on hyperlog, hyperkv, hyperlog-kdb-index; and P2P file sync over an append-only merkle DAG log.
02:16:37 - 02:28:33
WebRTC Swarm with Hyperlogs
Create a swarm of P2P connections using WebRTC and a signalhub. - https://github.com/mafintosh/webrtc-swarm