@cipherstash/protect-ffi 0.5.4
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/LICENSE.md +21 -0
- package/README.md +136 -0
- package/lib/index.cjs +83 -0
- package/lib/index.d.cts +45 -0
- package/lib/index.d.mts +1 -0
- package/lib/index.mjs +2 -0
- package/lib/load.cjs +18 -0
- package/lib/load.d.cts +1 -0
- package/package.json +61 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 CipherStash
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# protect-ffi
|
|
2
|
+
|
|
3
|
+
> [!IMPORTANT]
|
|
4
|
+
> If you are looking to implement this package into your application please use the official [protect package](https://github.com/cipherstash/protect).
|
|
5
|
+
|
|
6
|
+
This project provides the JS bindings for the CipherStash Client Rust SDK and is bootstrapped by [create-neon](https://www.npmjs.com/package/create-neon).
|
|
7
|
+
|
|
8
|
+
## Building
|
|
9
|
+
|
|
10
|
+
Building requires a [supported version of Node and Rust](https://github.com/neon-bindings/neon#platform-support).
|
|
11
|
+
|
|
12
|
+
To run the build, run:
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
$ npm run build
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
This command uses the [@neon-rs/cli](https://www.npmjs.com/package/@neon-rs/cli) utility to assemble the binary Node addon from the output of `cargo`.
|
|
19
|
+
|
|
20
|
+
## Exploring
|
|
21
|
+
|
|
22
|
+
After building `protect-ffi`, you can explore its exports at the Node console.
|
|
23
|
+
`CS_CLIENT_ID` and `CS_CLIENT_KEY` must be set in your environment for the call to `newClient()` to succeed.
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
$ npm i
|
|
27
|
+
$ npm run build
|
|
28
|
+
$ node
|
|
29
|
+
> const addon = require(".");
|
|
30
|
+
> const client = await addon.newClient();
|
|
31
|
+
> const ciphertext = await addon.encrypt(client, "plaintext", "column_name");
|
|
32
|
+
> const plaintext = await addon.decrypt(client, ciphertext);
|
|
33
|
+
> console.log({ciphertext, plaintext});
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Available Scripts
|
|
37
|
+
|
|
38
|
+
In the project directory, you can run:
|
|
39
|
+
|
|
40
|
+
#### `npm run build`
|
|
41
|
+
|
|
42
|
+
Builds the Node addon (`index.node`) from source, generating a release build with `cargo --release`.
|
|
43
|
+
|
|
44
|
+
Additional [`cargo build`](https://doc.rust-lang.org/cargo/commands/cargo-build.html) arguments may be passed to `npm run build` and similar commands. For example, to enable a [cargo feature](https://doc.rust-lang.org/cargo/reference/features.html):
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
npm run build -- --feature=beetle
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
#### `npm run debug`
|
|
51
|
+
|
|
52
|
+
Similar to `npm run build` but generates a debug build with `cargo`.
|
|
53
|
+
|
|
54
|
+
#### `npm run cross`
|
|
55
|
+
|
|
56
|
+
Similar to `npm run build` but uses [cross-rs](https://github.com/cross-rs/cross) to cross-compile for another platform. Use the [`CARGO_BUILD_TARGET`](https://doc.rust-lang.org/cargo/reference/config.html#buildtarget) environment variable to select the build target.
|
|
57
|
+
|
|
58
|
+
#### `npm run release`
|
|
59
|
+
|
|
60
|
+
Initiate a full build and publication of a new patch release of this library via GitHub Actions.
|
|
61
|
+
|
|
62
|
+
#### `npm run dryrun`
|
|
63
|
+
|
|
64
|
+
Initiate a dry run of a patch release of this library via GitHub Actions. This performs a full build but does not publish the final result.
|
|
65
|
+
|
|
66
|
+
#### `npm test`
|
|
67
|
+
|
|
68
|
+
Runs the unit tests by calling `cargo test`. You can learn more about [adding tests to your Rust code](https://doc.rust-lang.org/book/ch11-01-writing-tests.html) from the [Rust book](https://doc.rust-lang.org/book/).
|
|
69
|
+
|
|
70
|
+
## Project Layout
|
|
71
|
+
|
|
72
|
+
The directory structure of this project is:
|
|
73
|
+
|
|
74
|
+
```
|
|
75
|
+
protect-ffi/
|
|
76
|
+
├── Cargo.toml
|
|
77
|
+
├── README.md
|
|
78
|
+
├── lib/
|
|
79
|
+
├── src/
|
|
80
|
+
| ├── index.mts
|
|
81
|
+
| └── index.cts
|
|
82
|
+
├── crates/
|
|
83
|
+
| └── protect-ffi/
|
|
84
|
+
| └── src/
|
|
85
|
+
| └── lib.rs
|
|
86
|
+
├── platforms/
|
|
87
|
+
├── package.json
|
|
88
|
+
└── target/
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
| Entry | Purpose |
|
|
92
|
+
|----------------|------------------------------------------------------------------------------------------------------------------------------------------|
|
|
93
|
+
| `Cargo.toml` | The Cargo [manifest file](https://doc.rust-lang.org/cargo/reference/manifest.html), which informs the `cargo` command. |
|
|
94
|
+
| `README.md` | This file. |
|
|
95
|
+
| `lib/` | The directory containing the generated output from [tsc](https://typescriptlang.org). |
|
|
96
|
+
| `src/` | The directory containing the TypeScript source files. |
|
|
97
|
+
| `index.mts` | Entry point for when this library is loaded via [ESM `import`](https://nodejs.org/api/esm.html#modules-ecmascript-modules) syntax. |
|
|
98
|
+
| `index.cts` | Entry point for when this library is loaded via [CJS `require`](https://nodejs.org/api/modules.html#requireid). |
|
|
99
|
+
| `crates/` | The directory tree containing the Rust source code for the project. |
|
|
100
|
+
| `lib.rs` | Entry point for the Rust source code. |
|
|
101
|
+
| `platforms/` | The directory containing distributions of the binary addon backend for each platform supported by this library. |
|
|
102
|
+
| `package.json` | The npm [manifest file](https://docs.npmjs.com/cli/v7/configuring-npm/package-json), which informs the `npm` command. |
|
|
103
|
+
| `target/` | Binary artifacts generated by the Rust build. |
|
|
104
|
+
|
|
105
|
+
## Releasing
|
|
106
|
+
|
|
107
|
+
Releases are handled by GitHub Actions using a `workflow_dispatch` event trigger.
|
|
108
|
+
The [release workflow](./.github/workflows/release.yml) was generated by [Neon](https://neon-rs.dev/).
|
|
109
|
+
|
|
110
|
+
The release workflow is responsible for:
|
|
111
|
+
- Building and publishing the main `@cipherstash/protect-ffi` package as well as the native packages for each platform (e.g. `@cipherstash/protect-ffi-darwin-arm64`).
|
|
112
|
+
- Creating the GitHub release.
|
|
113
|
+
- Creating a Git tag for the version.
|
|
114
|
+
|
|
115
|
+
To perform a release:
|
|
116
|
+
1. Navigate to the ["Release" workflow page](https://github.com/cipherstash/protect-ffi/actions/workflows/release.yml) in GitHub.
|
|
117
|
+
1. Click on "Run workflow".
|
|
118
|
+
1. Select the branch to release from.
|
|
119
|
+
Use the default of "main" unless you want to do a pre-release version or dry run from a branch.
|
|
120
|
+
1. Select whether or not to do a dry run.
|
|
121
|
+
Dry runs are useful for verifying that the build will succeed for all platforms before doing a full run with a publish.
|
|
122
|
+
1. Choose a version to publish.
|
|
123
|
+
The options are similar to [`npm version`](https://docs.npmjs.com/cli/v11/commands/npm-version).
|
|
124
|
+
Select "custom" in the dropdown and fill in the "Custom version" text box if you want to use a semver string instead of the shorthand (patch, minor, major, etc.).
|
|
125
|
+
1. Click "Run workflow".
|
|
126
|
+
|
|
127
|
+
Note that we currently don't have any automation around release notes or a changelog.
|
|
128
|
+
However, you can add release notes after running the workflow by editing the release on GitHub.
|
|
129
|
+
|
|
130
|
+
## Learn More
|
|
131
|
+
|
|
132
|
+
Learn more about:
|
|
133
|
+
|
|
134
|
+
- [Neon](https://neon-bindings.com).
|
|
135
|
+
- [Rust](https://www.rust-lang.org).
|
|
136
|
+
- [Node](https://nodejs.org).
|
package/lib/index.cjs
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// This module is the CJS entry point for the library.
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
exports.newClient = newClient;
|
|
38
|
+
exports.encrypt = encrypt;
|
|
39
|
+
exports.decrypt = decrypt;
|
|
40
|
+
exports.encryptBulk = encryptBulk;
|
|
41
|
+
exports.decryptBulk = decryptBulk;
|
|
42
|
+
exports.decryptBulkFallible = decryptBulkFallible;
|
|
43
|
+
// The Rust addon.
|
|
44
|
+
const addon = __importStar(require("./load.cjs"));
|
|
45
|
+
function newClient() {
|
|
46
|
+
return addon.newClient();
|
|
47
|
+
}
|
|
48
|
+
function encrypt(client, plaintext, columnName, lockContext, ctsToken) {
|
|
49
|
+
if (ctsToken) {
|
|
50
|
+
return addon.encrypt(client, plaintext, columnName, lockContext, ctsToken);
|
|
51
|
+
}
|
|
52
|
+
if (lockContext) {
|
|
53
|
+
return addon.encrypt(client, plaintext, columnName, lockContext);
|
|
54
|
+
}
|
|
55
|
+
return addon.encrypt(client, plaintext, columnName);
|
|
56
|
+
}
|
|
57
|
+
function decrypt(client, ciphertext, lockContext, ctsToken) {
|
|
58
|
+
if (ctsToken) {
|
|
59
|
+
return addon.decrypt(client, ciphertext, lockContext, ctsToken);
|
|
60
|
+
}
|
|
61
|
+
if (lockContext) {
|
|
62
|
+
return addon.decrypt(client, ciphertext, lockContext);
|
|
63
|
+
}
|
|
64
|
+
return addon.decrypt(client, ciphertext);
|
|
65
|
+
}
|
|
66
|
+
function encryptBulk(client, plaintextTargets, ctsToken) {
|
|
67
|
+
if (ctsToken) {
|
|
68
|
+
return addon.encryptBulk(client, plaintextTargets, ctsToken);
|
|
69
|
+
}
|
|
70
|
+
return addon.encryptBulk(client, plaintextTargets);
|
|
71
|
+
}
|
|
72
|
+
function decryptBulk(client, ciphertexts, ctsToken) {
|
|
73
|
+
if (ctsToken) {
|
|
74
|
+
return addon.decryptBulk(client, ciphertexts, ctsToken);
|
|
75
|
+
}
|
|
76
|
+
return addon.decryptBulk(client, ciphertexts);
|
|
77
|
+
}
|
|
78
|
+
function decryptBulkFallible(client, ciphertexts, ctsToken) {
|
|
79
|
+
if (ctsToken) {
|
|
80
|
+
return addon.decryptBulkFallible(client, ciphertexts, ctsToken);
|
|
81
|
+
}
|
|
82
|
+
return addon.decryptBulkFallible(client, ciphertexts);
|
|
83
|
+
}
|
package/lib/index.d.cts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as addon from './load.cjs';
|
|
2
|
+
declare module './load.cjs' {
|
|
3
|
+
interface Client {
|
|
4
|
+
}
|
|
5
|
+
function newClient(): Promise<Client>;
|
|
6
|
+
function encrypt(client: Client, plaintext: string, columnName: string, context?: Context, ctsToken?: CtsToken): Promise<string>;
|
|
7
|
+
function decrypt(client: Client, ciphertext: string, context?: Context, ctsToken?: CtsToken): Promise<string>;
|
|
8
|
+
function encryptBulk(client: Client, plaintextTargets: BulkEncryptPayload[], ctsToken?: CtsToken): Promise<string[]>;
|
|
9
|
+
function decryptBulk(client: Client, ciphertexts: BulkDecryptPayload[], ctsToken?: CtsToken): Promise<string[]>;
|
|
10
|
+
function decryptBulkFallible(client: Client, ciphertexts: BulkDecryptPayload[], ctsToken?: CtsToken): Promise<DecryptResult[]>;
|
|
11
|
+
}
|
|
12
|
+
export type DecryptResult = {
|
|
13
|
+
data: string;
|
|
14
|
+
} | {
|
|
15
|
+
error: string;
|
|
16
|
+
};
|
|
17
|
+
export declare function newClient(): Promise<addon.Client>;
|
|
18
|
+
export declare function encrypt(client: addon.Client, plaintext: string, columnName: string, lockContext?: Context, ctsToken?: CtsToken): Promise<string>;
|
|
19
|
+
export declare function decrypt(client: addon.Client, ciphertext: string, lockContext?: Context, ctsToken?: CtsToken): Promise<string>;
|
|
20
|
+
export declare function encryptBulk(client: addon.Client, plaintextTargets: BulkEncryptPayload[], ctsToken?: CtsToken): Promise<string[]>;
|
|
21
|
+
export declare function decryptBulk(client: addon.Client, ciphertexts: BulkDecryptPayload[], ctsToken?: CtsToken): Promise<string[]>;
|
|
22
|
+
export declare function decryptBulkFallible(client: addon.Client, ciphertexts: BulkDecryptPayload[], ctsToken?: CtsToken): Promise<DecryptResult[]>;
|
|
23
|
+
export type BulkEncryptPayload = {
|
|
24
|
+
plaintext: string;
|
|
25
|
+
column: string;
|
|
26
|
+
lockContext?: Context;
|
|
27
|
+
};
|
|
28
|
+
export type BulkDecryptPayload = {
|
|
29
|
+
ciphertext: string;
|
|
30
|
+
lockContext?: Context;
|
|
31
|
+
};
|
|
32
|
+
export type CtsToken = {
|
|
33
|
+
accessToken: string;
|
|
34
|
+
expiry: number;
|
|
35
|
+
};
|
|
36
|
+
export type Context = {
|
|
37
|
+
identityClaim: string[];
|
|
38
|
+
};
|
|
39
|
+
export type EncryptedEqlPayload = {
|
|
40
|
+
c: string;
|
|
41
|
+
};
|
|
42
|
+
export type BulkEncryptedEqlPayload = {
|
|
43
|
+
c: string;
|
|
44
|
+
id: string;
|
|
45
|
+
}[];
|
package/lib/index.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './index.cjs';
|
package/lib/index.mjs
ADDED
package/lib/load.cjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// This module loads the platform-specific build of the addon on
|
|
3
|
+
// the current system. The supported platforms are registered in
|
|
4
|
+
// the `platforms` object below, whose entries can be managed by
|
|
5
|
+
// by the Neon CLI:
|
|
6
|
+
//
|
|
7
|
+
// https://www.npmjs.com/package/@neon-rs/cli
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
module.exports = require('@neon-rs/load').proxy({
|
|
10
|
+
platforms: {
|
|
11
|
+
'win32-x64-msvc': () => require('@cipherstash/protect-ffi-win32-x64-msvc'),
|
|
12
|
+
'darwin-x64': () => require('@cipherstash/protect-ffi-darwin-x64'),
|
|
13
|
+
'darwin-arm64': () => require('@cipherstash/protect-ffi-darwin-arm64'),
|
|
14
|
+
'linux-x64-gnu': () => require('@cipherstash/protect-ffi-linux-x64-gnu'),
|
|
15
|
+
'linux-arm64-gnu': () => require('@cipherstash/protect-ffi-linux-arm64-gnu'),
|
|
16
|
+
},
|
|
17
|
+
debug: () => require('../index.node'),
|
|
18
|
+
});
|
package/lib/load.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cipherstash/protect-ffi",
|
|
3
|
+
"version": "0.5.4",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "./lib/index.cjs",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "tsc &&cargo test",
|
|
8
|
+
"cargo-build": "tsc &&cargo build --message-format=json-render-diagnostics > cargo.log",
|
|
9
|
+
"cross-build": "tsc &&cross build --message-format=json-render-diagnostics > cross.log",
|
|
10
|
+
"postcargo-build": "neon dist < cargo.log",
|
|
11
|
+
"postcross-build": "neon dist -m /target < cross.log",
|
|
12
|
+
"debug": "npm run cargo-build --",
|
|
13
|
+
"build": "npm run cargo-build -- --release",
|
|
14
|
+
"cross": "npm run cross-build -- --release",
|
|
15
|
+
"prepack": "tsc &&neon update",
|
|
16
|
+
"version": "neon bump --binaries platforms && git add .",
|
|
17
|
+
"release": "gh workflow run release.yml -f dryrun=false -f version=patch",
|
|
18
|
+
"dryrun": "gh workflow run publish.yml -f dryrun=true"
|
|
19
|
+
},
|
|
20
|
+
"author": "",
|
|
21
|
+
"license": "ISC",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"import": {
|
|
25
|
+
"types": "./lib/index.d.mts",
|
|
26
|
+
"default": "./lib/index.mjs"
|
|
27
|
+
},
|
|
28
|
+
"require": {
|
|
29
|
+
"types": "./lib/index.d.cts",
|
|
30
|
+
"default": "./lib/index.cjs"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"types": "./lib/index.d.cts",
|
|
35
|
+
"files": [
|
|
36
|
+
"lib/**/*.?({c,m}){t,j}s"
|
|
37
|
+
],
|
|
38
|
+
"neon": {
|
|
39
|
+
"type": "library",
|
|
40
|
+
"org": "@cipherstash",
|
|
41
|
+
"platforms": "common",
|
|
42
|
+
"load": "./src/load.cts",
|
|
43
|
+
"prefix": "protect-ffi-"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@neon-rs/cli": "^0.1.82",
|
|
47
|
+
"@tsconfig/node20": "^20.1.4",
|
|
48
|
+
"@types/node": "^20.11.16",
|
|
49
|
+
"typescript": "^5.3.3"
|
|
50
|
+
},
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"@neon-rs/load": "^0.1.82"
|
|
53
|
+
},
|
|
54
|
+
"optionalDependencies": {
|
|
55
|
+
"@cipherstash/protect-ffi-win32-x64-msvc": "0.5.4",
|
|
56
|
+
"@cipherstash/protect-ffi-darwin-x64": "0.5.4",
|
|
57
|
+
"@cipherstash/protect-ffi-darwin-arm64": "0.5.4",
|
|
58
|
+
"@cipherstash/protect-ffi-linux-x64-gnu": "0.5.4",
|
|
59
|
+
"@cipherstash/protect-ffi-linux-arm64-gnu": "0.5.4"
|
|
60
|
+
}
|
|
61
|
+
}
|