@delali/sirannon-sqlite 0.3.6-next.77 → 0.3.6-next.78

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/NOTICE CHANGED
@@ -38,9 +38,25 @@ This product includes code from these projects:
38
38
  2017 Node.js API collaborators, licensed under the MIT License. Each
39
39
  @delali/sirannon-sqlite-<platform> package contains code compiled from
40
40
  node-addon-api's headers.
41
+ - SQLite3 Multiple Ciphers
42
+ (https://github.com/utelle/SQLite3MultipleCiphers), Copyright (c) 2006-2026
43
+ Ulrich Telle, licensed under the MIT License. Each
44
+ @delali/sirannon-sqlite-<platform> package contains SQLite3 Multiple
45
+ Ciphers compiled from its amalgamation, with the patches in
46
+ native/sqlite/patches/sqlite applied. That amalgamation also contains the
47
+ code in the next three entries.
48
+ - The AEGIS library, Copyright (c) 2023-2024 Frank Denis, licensed under the
49
+ MIT License, which SQLite3 Multiple Ciphers carries for its AEGIS cipher.
50
+ - The FIPS 180-2 SHA-224/256/384/512 implementation, Copyright (C) 2005, 2007
51
+ Olivier Gay, licensed under the BSD 3-Clause License.
52
+ - The Argon2 reference implementation, Copyright 2015 Daniel Dinu, Dmitry
53
+ Khovratovich, Jean-Philippe Aumasson, and Samuel Neves, which its authors
54
+ offer under CC0 1.0 or the Apache License, Version 2.0. Sirannon uses it
55
+ under the Apache License, Version 2.0.
41
56
 
42
57
  The MIT License grants the following permission for libSQL, node-gyp,
43
- better-sqlite3, and node-addon-api:
58
+ better-sqlite3, node-addon-api, SQLite3 Multiple Ciphers, and the AEGIS
59
+ library:
44
60
 
45
61
  Permission is hereby granted, free of charge, to any person obtaining a copy
46
62
  of this software and associated documentation files (the "Software"), to deal
@@ -59,3 +75,33 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
59
75
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
60
76
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
61
77
  SOFTWARE.
78
+
79
+ The BSD 3-Clause License grants the following permission for the FIPS 180-2
80
+ SHA-224/256/384/512 implementation:
81
+
82
+ Copyright (C) 2005, 2007 Olivier Gay <olivier.gay@a3.epfl.ch>
83
+ All rights reserved.
84
+
85
+ Redistribution and use in source and binary forms, with or without
86
+ modification, are permitted provided that the following conditions
87
+ are met:
88
+ 1. Redistributions of source code must retain the above copyright
89
+ notice, this list of conditions and the following disclaimer.
90
+ 2. Redistributions in binary form must reproduce the above copyright
91
+ notice, this list of conditions and the following disclaimer in the
92
+ documentation and/or other materials provided with the distribution.
93
+ 3. Neither the name of the project nor the names of its contributors
94
+ may be used to endorse or promote products derived from this software
95
+ without specific prior written permission.
96
+
97
+ THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
98
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
99
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
100
+ ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
101
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
102
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
103
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
104
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
105
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
106
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
107
+ SUCH DAMAGE.
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [![npm](https://img.shields.io/npm/v/@delali/sirannon-sqlite)](https://www.npmjs.com/package/@delali/sirannon-sqlite)
4
4
  [![license](https://img.shields.io/npm/l/@delali/sirannon-sqlite)](https://github.com/assetcorp/sirannon-db/blob/main/LICENSE)
5
5
 
6
- This package contains better-sqlite3 13.0.2, built against Sirannon's own build of SQLite, which counts the rows that each statement reads and writes. When you pass `rowCounts: true`, Sirannon's better-sqlite3 driver loads this package and reports both counts for every statement through `onQueryComplete`, so that a host that puts many tenants on one machine can bill each of them.
6
+ This package contains better-sqlite3 13.0.2, built against Sirannon's build of SQLite, which is SQLite3 Multiple Ciphers with a patch that counts the rows that each statement reads and writes. When you pass `rowCounts: true`, Sirannon's better-sqlite3 driver loads this package and reports both counts for every statement through `onQueryComplete`, so that a host that puts many tenants on one machine can bill each of them. When you pass `encryption: true`, the driver loads this package and keeps every page of a database that you open with the `encryption` option as ciphertext, as the [encryption guide](https://github.com/assetcorp/sirannon-db/blob/main/docs/encryption.md) describes.
7
7
 
8
8
  ## Install
9
9
 
@@ -21,16 +21,23 @@ const sirannon = new Sirannon({
21
21
  driver: betterSqlite3({ rowCounts: true }),
22
22
  metrics: { onQueryComplete: m => console.log(m.databaseId, m.rowsRead, m.rowsWritten) },
23
23
  })
24
+
25
+ const encrypting = new Sirannon({ driver: betterSqlite3({ encryption: true }) })
26
+ const ledger = await encrypting.open('ledger', './ledger.db', { encryption: { key: loadLedgerKey } })
24
27
  ```
25
28
 
29
+ `loadLedgerKey` stands for a function of yours that returns the 32 key bytes from a key service or a keychain.
30
+
26
31
  This package lists six platform packages as optional dependencies, so npm installs only the one whose `os` and `cpu` match your host. The release workflow publishes all seven packages at the library's version, and this package requires exactly that version of each platform package.
27
32
 
28
33
  ## What it contains
29
34
 
30
- The `lib` directory contains better-sqlite3's JavaScript, unchanged. Sirannon compiles the native module from better-sqlite3's C++ source and the SQLite amalgamation, after it applies each patch in the repository's `native/sqlite/patches` directory. The first SQLite patch is Cloudflare's row-counting patch, which Sirannon changed to widen both counters to 64 bits and to leave the work of its own change-capture triggers out of both counts, and the first better-sqlite3 patch adds the `takeRowCounts` method that reads them. The counting rules are in the [core engine guide](https://github.com/assetcorp/sirannon-db/blob/main/docs/core.md#rows-read-and-rows-written).
35
+ The `lib` directory contains better-sqlite3's JavaScript, unchanged. Sirannon compiles the native module from better-sqlite3's C++ source and the SQLite3 Multiple Ciphers 2.6.1 amalgamation, which carries SQLite 3.54.0, after it applies each patch in the repository's `native/sqlite/patches` directory. The first SQLite patch is Cloudflare's row-counting patch, which Sirannon changed to widen both counters to 64 bits and to leave the work of its own change-capture triggers out of both counts, and the first better-sqlite3 patch adds the `takeRowCounts` method that reads them. The counting rules are in the [core engine guide](https://github.com/assetcorp/sirannon-db/blob/main/docs/core.md#rows-read-and-rows-written).
36
+
37
+ The second SQLite patch adds the `sirannon_export` function, which copies the main database into an attached database under that database's key and keeps the rowid of every row, as `VACUUM INTO` does. The second better-sqlite3 patch adds the `key` method that hands SQLite3 Multiple Ciphers a raw 32-byte key, keys the destination of a backup with the source's key, and adds the calls that record a connection's changes through SQLite's session extension, so that a key change can apply the writes that commit while it copies the file. SQLite3 Multiple Ciphers encrypts each page with AEGIS-256, from code that is compiled into the native module.
31
38
 
32
- On a platform without a published build, the driver throws `ROW_COUNTS_UNSUPPORTED` when it opens a database. Compile a build with `native/sqlite/build.mjs` from the repository, and pass its path to the driver as `sqliteBindingPath`.
39
+ On a platform without a published build, the driver throws `ROW_COUNTS_UNSUPPORTED` or `ENCRYPTION_UNSUPPORTED` when it opens a database. Compile a build with `native/sqlite/build.mjs` from the repository, and pass its path to the driver as `sqliteBindingPath`.
33
40
 
34
41
  ## Licence
35
42
 
36
- The Apache-2.0 and MIT licences cover this package. Each project whose code is in this package has its name and licence in the package's `NOTICE` file, and the patches, the build script, and the tests are in [assetcorp/sirannon-db](https://github.com/assetcorp/sirannon-db).
43
+ The Apache-2.0 and MIT licences cover this package, and the BSD-3-Clause licence also covers each platform package, since the SQLite3 Multiple Ciphers amalgamation in those carries a SHA-2 implementation under that licence. Each project whose code is in this package has its name and licence in the package's `NOTICE` file, and the patches, the build script, and the tests are in [assetcorp/sirannon-db](https://github.com/assetcorp/sirannon-db).
package/index.d.ts CHANGED
@@ -1,6 +1,20 @@
1
1
  import BetterSqlite3 = require('better-sqlite3')
2
2
 
3
- declare const Database: typeof BetterSqlite3 & {
3
+ declare namespace Database {
4
+ interface SirannonDatabase extends BetterSqlite3.Database {
5
+ key(rawKey: Uint8Array): this
6
+ startChangeCapture(): this
7
+ takeCapturedChanges(): Buffer
8
+ stopChangeCapture(): this
9
+ applyChanges(changes: Uint8Array): this
10
+ }
11
+ }
12
+
13
+ declare const Database: {
14
+ new (filename?: string | Buffer, options?: BetterSqlite3.Options): Database.SirannonDatabase
15
+ (filename?: string | Buffer, options?: BetterSqlite3.Options): Database.SirannonDatabase
16
+ prototype: Database.SirannonDatabase
17
+ SqliteError: typeof BetterSqlite3.SqliteError
4
18
  bindingPath(): string | null
5
19
  }
6
20
 
package/index.js CHANGED
@@ -2,6 +2,7 @@ const { existsSync } = require('node:fs')
2
2
  const { dirname, join, resolve } = require('node:path')
3
3
  const createDatabase = require('./lib/database')
4
4
  const SqliteError = require('./lib/sqlite-error')
5
+ const { cppdb } = require('./lib/util')
5
6
 
6
7
  const ADDON_FILE_NAME = 'better_sqlite3.node'
7
8
  const MUSL_DIRECTORY = 'musl'
@@ -54,6 +55,32 @@ function loadAddon(nativeBinding) {
54
55
  return require(path)
55
56
  }
56
57
 
57
- module.exports = createDatabase(loadAddon, true)
58
+ const Database = createDatabase(loadAddon, true)
59
+
60
+ Database.prototype.key = function key(rawKey) {
61
+ this[cppdb].key(rawKey)
62
+ return this
63
+ }
64
+
65
+ Database.prototype.startChangeCapture = function startChangeCapture() {
66
+ this[cppdb].startChangeCapture()
67
+ return this
68
+ }
69
+
70
+ Database.prototype.takeCapturedChanges = function takeCapturedChanges() {
71
+ return this[cppdb].takeCapturedChanges()
72
+ }
73
+
74
+ Database.prototype.stopChangeCapture = function stopChangeCapture() {
75
+ this[cppdb].stopChangeCapture()
76
+ return this
77
+ }
78
+
79
+ Database.prototype.applyChanges = function applyChanges(changes) {
80
+ this[cppdb].applyChanges(changes)
81
+ return this
82
+ }
83
+
84
+ module.exports = Database
58
85
  module.exports.SqliteError = SqliteError
59
86
  module.exports.bindingPath = bindingPath
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@delali/sirannon-sqlite",
3
- "version": "0.3.6-next.77",
4
- "description": "better-sqlite3 built against Sirannon's build of SQLite, which counts the rows that each statement reads and writes so that Sirannon can report them for per-tenant metering.",
3
+ "version": "0.3.6-next.78",
4
+ "description": "better-sqlite3 built against Sirannon's build of SQLite3 Multiple Ciphers, which encrypts every page of a database with AEGIS-256 under a 32-byte key and counts the rows that each statement reads and writes so that Sirannon can report them for per-tenant metering.",
5
5
  "license": "Apache-2.0 AND MIT",
6
6
  "author": "Delali (https://sondelali.com)",
7
7
  "homepage": "https://github.com/assetcorp/sirannon-db",
@@ -33,11 +33,11 @@
33
33
  "@types/better-sqlite3": "7.6.13"
34
34
  },
35
35
  "optionalDependencies": {
36
- "@delali/sirannon-sqlite-darwin-arm64": "0.3.6-next.77",
37
- "@delali/sirannon-sqlite-darwin-x64": "0.3.6-next.77",
38
- "@delali/sirannon-sqlite-linux-arm64": "0.3.6-next.77",
39
- "@delali/sirannon-sqlite-linux-x64": "0.3.6-next.77",
40
- "@delali/sirannon-sqlite-win32-arm64": "0.3.6-next.77",
41
- "@delali/sirannon-sqlite-win32-x64": "0.3.6-next.77"
36
+ "@delali/sirannon-sqlite-darwin-arm64": "0.3.6-next.78",
37
+ "@delali/sirannon-sqlite-darwin-x64": "0.3.6-next.78",
38
+ "@delali/sirannon-sqlite-linux-arm64": "0.3.6-next.78",
39
+ "@delali/sirannon-sqlite-linux-x64": "0.3.6-next.78",
40
+ "@delali/sirannon-sqlite-win32-arm64": "0.3.6-next.78",
41
+ "@delali/sirannon-sqlite-win32-x64": "0.3.6-next.78"
42
42
  }
43
43
  }