@armortext/sqlcipher

0.1.5 • Public • Published

@armortext/sqlcipher

Cross-platform (win32-x64, darwin-x64, linux-x64) binary distribution of sqlite3 with sqlcipher and fts support

This is experimental work and has not been tested in production deployments yet.

The intent of this package is to script use of node-sqlite3 and node-pre-gyp for building, packaging and deploying binaries of sqlite3 with sqlcipher and fts extensions targeting latest node-webkit (0.23.7, 0.24.4, 0.25.4, 0.26.6, 0.27.1), electron (1.7.x, 1.8.x) and node (8.9.3, 9.3.0).

When building app for node-webkit or electron we tend to prepare binary for target platform as part of the build process, so there is no need for node-pre-gyp and its dependencies at runtime, the only dependency that we need is semver.

In 0.1.x builds we are going to use the following:

  • OpenSSL will be rebuilt from node deps openssl source (node-9.3.0, openssl-1.0.2m) with crypto that is required for SQLCipher and linked statically (electron does not expose openssl crypto symbols, database gets corrupted on node-webkit if dynamically linking with its openssl on macOS).
  • When possible it will fallback to dynamically linked crypto that is bundled with node instead of rebuilding it.
  • SQLCipher will be based on https://github.com/sqlcipher/sqlcipher/tree/v3.4.1, patched (can be skipped) to build sqlite3 amalgamation tar file.

In the future we might consider switching to https://conan.io for openssl / sqlcipher libraries and get npm package rebuilt by TravisCI and Appveyor, but we are not there yet.

It does not seem likely that we can use dockcross to produce libraries for windows - https://github.com/nodejs/node-gyp/issues/660, so they have to be built on windows boxes (unless clang can be used for cross-builds, i.e. via wclang).

Currently we use curl and tar installed on the box when building from source, this should be moved to javascript or python (used via binding.gyp) to have less dependencies / make it more portable.

We should also consider supporting other crypto options, like LibTomCrypt / BoringSSL / LibreSSL and no-asm option for OpenSSL when linking crypto statically for electron / node-webkit.

In 0.2.x we probably should switch from NAN to N-API and move this module to github:

https://nodejs.org/docs/latest/api/n-api.html https://github.com/nodejs/abi-stable-node https://github.com/mhdawson/node-sqlite3/tree/node-addon-api

# some global setup to be able to build local modules
# on linux that might need to be prefixed with sudo and 
npm install -g node-gyp
npm install -g node-pre-gyp
npm install -g nw-gyp
# install run node-webkit and electron globally (optional)
npm install -g nw@0.27.1-sdk
npm install -g electron@1.8.2-beta.3
# setup windows-build-tools if building from source on windows
npm install -g --prod --add-python-to-path windows-build-tools
# to prepare dependencies in case some tools (curl, tar) are not installed by running it via docker
npm run docker-deps
# patch nw-gyp if building from source on linux
./linux-patch-nw-gyp.sh
# for quick demo in node-webkit and electron that installed as dev dependencies
npm run quick-demo
npm run demo
npm run clean-all
# quick check with latest public version and globally installed node-webkit and electron
(cd /tmp &&\
 rm -rf sqlcipher-demo &&\
 mkdir -p sqlcipher-demo &&\
 cd sqlcipher-demo &&\
 npm install @armortext/sqlcipher --only=prod &&\
 cd node_modules/@armortext/sqlcipher &&\
 npm run demo &&\
 npm run electron-check &&\
 npm run nw-check &&\
 npm run clean-all)
# to download electron and node-webkit as part of the demo when they are not installed globally
(cd /tmp &&\
 rm -rf sqlcipher-demo &&\
 mkdir -p sqlcipher-demo &&\
 cd sqlcipher-demo &&\
 npm install @armortext/sqlcipher --only=prod &&\
 cd node_modules/@armortext/sqlcipher &&\
 npm run demo &&\
 npm run electron-demo &&\
 npm run nw-demo &&\
 npm run clean-all)
# to make latest binaries for a particular platform available and to publish package to npmjs.com
npm install
npm run deploy
npm publish --access public
npm run clean
# in case we are building for linux on some other platform (i.e. macOS) we'll just use docker
npm run linux-deploy
# to build and publish for node-webkit and electron
npm install --runtime=node-webkit --target=0.27.1 --target_arch=x64 --build-from-source
./node_modules/.bin/node-pre-gyp unpublish --runtime=node-webkit --target=0.27.1 --target_arch=x64
./node_modules/.bin/node-pre-gyp package publish --runtime=node-webkit --target=0.27.1 --target_arch=x64
npm install --runtime=electron --target=1.8.2-beta.3 --target_arch=x64 --build-from-source
./node_modules/.bin/node-pre-gyp unpublish --runtime=electron --target=1.8.2-beta.3 --target_arch=x64
./node_modules/.bin/node-pre-gyp package publish --runtime=electron --target=1.8.2-beta.3 --target_arch=x64
npm run clean
# to check binary published for node-webkit and electron distributions
npm run quick-check
npm run clean-all
# to (re)install binary for a specific node-webkit and electron distributions as part of build process
npm install --only=prod
node-pre-gyp install --runtime=node-webkit --target=0.27.1 --target_arch=x64 --target_platform=linux --update-binary
node-pre-gyp install --runtime=electron --target=1.8.2-beta.3 --target_arch=x64 --target_platform=linux --update-binary
npm install shelljs yargs --no-save && npm run clean
# install prod dependencies
npm i semver --save

# install dev dependencies
npm i shelljs yargs node-pre-gyp --save-dev

# for node.js
npm i @armortext/sqlcipher

# for node-webkit
npm i @armortext/sqlcipher --runtime=node-webkit --target=0.27.1 --target_arch=x64

# for electron
npm i @armortext/sqlcipher --runtime=electron --target=1.8.2-beta.3 --target_arch=x64

# from a mirror
npm i @armortext/sqlcipher --sqlcipher_binary_host_mirror=https://cdn.armortext.com
const sqlcipher = require('@armortext/sqlcipher').verbose();
const db = new sqlcipher.Database('test.db');

db.serialize(function() {
  db.run("PRAGMA KEY = 'secret'");
  db.run("PRAGMA CIPHER = 'aes-256-cbc'");

  db.run("DROP TABLE IF EXISTS lorem");
  db.run("CREATE TABLE lorem (info TEXT)");

  const stmt = db.prepare("INSERT INTO lorem VALUES (?)");
  for (let i = 0; i < 10; i++) {
    stmt.run("Ipsum " + i);
  }
  stmt.finalize();

  db.each("SELECT rowid AS id, info FROM lorem", function(err, row) {
    console.log(row.id + ": " + row.info);
  });
});

db.close();

Readme

Keywords

none

Package Sidebar

Install

npm i @armortext/sqlcipher

Weekly Downloads

1

Version

0.1.5

License

BSD-3-Clause

Last publish

Collaborators

  • gryphn-admin
  • armortext-admin