Creating a client is a quick process, but remember that these credentials are private and should be handled with care. If these credentials are lost there is no way to recover your data, as we do not store them by default.
import e3db
token = 'YOUR_REGISTRATION_TOKEN_HERE'
client_name = 'example name'
public_key, private_key = e3db.Client.generate_keypair()
# Register your client
client_info = e3db.Client.register(token, client_name, public_key)
config = e3db.Config(
client_info.client_id,
client_info.api_key_id,
client_info.api_secret,
public_key,
private_key
)
# To save this Configuration to disk, do the following:
config.write()
# Instantiate your client to communicate with TozStore
client = e3db.Client(config())
3. Encrypt Your Data
Tozny's SDKs handle the encryption for you, all you need to provide is the data. See Record Structure for details on how you can best structure your data.
const e3db = require('e3db')
let client = new e3db.Client(/* config */)
async function main() {
let data = {
'first_name': 'Jon',
'last_name': 'Snow',
'phone': '555-555-1212',
}
let metadata = {
'house' : 'Stark'
}
let record = await client.write('contact', data, metadata)
console.log('Wrote record ' + record.meta.recordId)
}
main()
<?php
$data = [
'name' => 'Jon Snow',
'what_he_knows' => 'Nothing',
];
$metadata = [
'house' => 'Stark'
];
// 'test-contact' represents our data type
$record = $client->write('test-contact', $data, $metadata);
//record contains the newly created value
$record_id = $record->meta->record_id;
?>
// Create data for a record
var recordData map[string]string
recordType := "contact"
recordData["first_name"] = "Jon"
recordData["last_name"] = "Snow"
recordData["phone"] = "555-555-1212"
// Create optional metadata for the record
//(metadata can be used for searching)
var metadata map[string]string
matadata["realm"] = "The North"
metadata["pet"] = "Ghost"
// Encrypt and save the record
recordID, err := client.Write(
context.Background(),
recordType,
recordData,
metadata
)
if err != nil {
//Error handling omitted
}
fmt.Println("Wrote record: " + recordID)
record = client.write('contact', {
:first_name => 'Jon',
:last_name => 'Snow',
:phone => '555-555-1212'
})
printf("Wrote record %s\n", record.meta.record_id)
Client client = ...; // Get a client instance
Map<String, String> lyric = new HashMap<>();
lyric.put("line", "Say I'm the only bee in your bonnet");
lyric.put("song", "Birdhouse in Your Soul");
lyric.put("artist", "They Might Be Giants");
String recordType = "lyric";
client.write(recordType, new RecordData(lyric), null, new ResultHandler<Record>() {
@Override
public void handle(Result<Record> r) {
if(! r.isError()) {
// record written successfully
Record record = r.asValue();
// Log or print record ID, e.g.:
System.out.println("Record ID: " + record.meta().recordId());
}
else {
// an error occurred
throw new RuntimeException(r.asError().other());
}
}
}
);
// Wrap message in RecordData type to designate
// it as sensitive information for encryption
let recordData = RecordData(cleartext: ["SSN": "123-45-6789"])
// Can optionally include arbitrary metadata as `plain`
// where neither keys nor values are encrypted
e3db.write(type: "UserInfo", data: recordData, plain: ["Sent from": "my iPhone"]) { result in
switch result {
// The operation was successful, here's the record
case .success(let record):
// `record.meta` holds metadata associated
// with the record, such as type.
print("Wrote record! \(record.meta.recordId)")
case .failure(let error):
print("An error occurred attempting to write the data: \(error)")
}
}
}