Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

TozStore Minimal Example

node v8.17.0
version: 6.0.0
endpointsharetweet
This is a minimal implementation of TozStore, an end-to-end encryption service. This example breaks down the steps required to instantiate a client, write (encrypt) a record, and read (decrypt) a record.
const e3db = require("e3db")
Use the TozStore Dashboard to generate a full set of client credentials. You will use these values to create a Config object. The Config object will be used to instiate your client instance.
const config = new e3db.Config( process.env.CLIENT_ID, // A unique TozStore client id. process.env.API_KEY_ID, process.env.API_SECRET, process.env.PUBLIC_KEY, // PUBLIC - other clients will need for sharing. process.env.PRIVATE_KEY, // *PRIVATE - should ONLY be available to this client.* process.env.API_URL, process.env.PUBLIC_SIGNING_KEY, process.env.PRIVATE_SIGNING_KEY )
These credentials include your client's `private_key`. You must keep this key secure to protect the security of your data. In this example, the client's credentials are included as environment variables.
Use your Config object to instantiate your client instance.
const client = new e3db.Client(config)
The client provides the main API for TozStore operations. You can write records using client.write().
A record can be any json object. You will need to decide on a `type` for your record. Keep in mind, you can share records with other TozStore clients by type, and you can then unshare that type later.
const record1 = { key1: 'value1', key2: 'value2', key3: 'value3' } const type1 = 'type1' client.write(type1, record1) .then(record => { console.log(record) console.log(record.data) console.log(record.meta) console.log(record.meta.recordId) return record })
client.query(null, null, null, 'type1').next() .then(found => { console.log(found) return found })
Loading…

no comments

    sign in to comment