Skip to main content

Getting started

Prerequisites

Installation

The latest version of CYBERCRYPT D1 Sequelize can be installed through npm.org, using the following command:

npm install @cybercryptio/d1-sequelize

Usage

Choose confidential properties

In order to mark a property as confidential, you have to add the confidential attribute to the property.

Document = sequelize.define('Document', {
document: {
type: DataTypes.STRING,
confidential: true // Here
},
metadata: DataTypes.STRING
})

Initialize D1 Sequelize

D1 Sequelize must be able to communicate with the D1 service. For more information on how to configure the D1 client, see the D1 Client documentation.

This is done by initializing the integration like this:

const { D1GenericClient, UsernamePasswordCredentials } = require('@cybercryptio/d1-client-nodejs')
const d1Sequelize = require('@cybercryptio/d1-sequelize')

const endpoint = 'localhost:9000'
const uid = "UID"
const password = "PASSWORD"
const creds = new UsernamePasswordCredentials(uid, password, endpoint)
const client = new D1GenericClient(endpoint, creds)

d1Sequelize.d1Init(client)

Add hooks

In order for the encryption and decryption to work, you have to add two hooks to the model or globally.

const d1Sequelize = require('@cybercryptio/d1-sequelize')

Document = sequelize.define('Document', {
document: {
type: DataTypes.STRING,
confidential: true
},
metadata: DataTypes.STRING
}, {
hooks: {
beforeSave: d1Sequelize.encryptHook, // Here
afterFind: d1Sequelize.decryptHook // Here
}
})