Skip to content

Commit 2c40cf1

Browse files
Neon packaging (#75)
Removed the native directory. Made the tests run expecting the same structure as what we distribute. That same structure is created by either running `yarn compile` or `node-pre-gyp install` (the second being how and end user gets the binary). The publish structure is the same other than the new entry point, so that should continue working. * Add NAPI to changelog, would be good to remember * bump-version: Set release version 0.8.0-pre.1 * Add a comment to clarify where changes happen Limited jest `maxWorkers` to dodge the weird GH issue tracked by jestjs/jest#10662 but won't impact local machine runs as much Co-authored-by: Leeroy Travis <ops@ironcorelabs.com>
1 parent d416df5 commit 2c40cf1

27 files changed

+58
-388
lines changed

.github/rust-ci-patch.yaml

-7
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,3 @@
33
path: /jobs/cargo-test
44
- op: remove
55
path: /jobs/coverage
6-
7-
# Everything needs to run in the native directory.
8-
- op: add
9-
path: /defaults
10-
value:
11-
run:
12-
working-directory: native

.github/rust-daily-patch.yaml

-6
This file was deleted.

.github/workflows/rust-ci.yaml

-3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,3 @@ jobs:
4949
with:
5050
command: clippy
5151
args: ${{ env.clippy_args }}
52-
defaults:
53-
run:
54-
working-directory: native

.github/workflows/rust-daily.yaml

-3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,3 @@ jobs:
5252
- name: Print sccache stats
5353
if: steps.rust-cache.outputs.cache-hit != 'true'
5454
run: sccache -s
55-
defaults:
56-
run:
57-
working-directory: native

.gitignore

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
.babelrc
55
npm-debug.log
66
yarn-error.log
7-
native/target
8-
native/artifacts.json
9-
native/index.node
7+
target
8+
artifacts.json
109
dist/*
1110
bin-package/*
1211
build/*

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
- Added support for Node 16.
1010
- Upgraded Recrypt to 0.13
11+
- Upgraded to Neon's NAPI interface.
1112

1213
## 0.7.3
1314

native/Cargo.lock Cargo.lock

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

native/Cargo.toml Cargo.toml

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "recrypt-node-binding"
3-
version = "0.7.4-pre.22"
3+
version = "0.8.0-pre.1"
44
authors = ["IronCore Labs <code@ironcorelabs.com>"]
55
edition = "2021"
66
rust-version = "1.56.0"
@@ -13,9 +13,6 @@ crate-type = ["cdylib"]
1313
neon = { version = "0.9", default-features = false, features = ["napi-4"] }
1414
recrypt = "0.13.1"
1515

16-
[build-dependencies]
17-
neon-build = "0.9"
18-
1916
[profile.release]
2017
lto = true
2118
debug = false

benchmark/computePublicKey.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const Benchmark = require("benchmark");
2-
const recrypt = require("../native/index.node");
2+
const recrypt = require("../index.node");
33

44
const api = new recrypt.Api256();
55

benchmark/decryptLevelOne.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const Benchmark = require("benchmark");
2-
const recrypt = require("../native/index.node");
2+
const recrypt = require("../index.node");
33
//Randomly generated legit ED25519 keypair
44
const privateSigningKey = Buffer.from("O7f2FYsabKOFj3enK+HQ+cBmTMbAG6aCesd1nLcFM1wtA9XHg0+rFIVA7+nomADjEbJ1R/Gd+xHBO79UnLqxDQ==", "base64");
55

benchmark/decryptLevelTwo.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const Benchmark = require("benchmark");
2-
const recrypt = require("../native/index.node");
2+
const recrypt = require("../index.node");
33
//Randomly generated legit ED25519 keypair
44
const privateSigningKey = Buffer.from("O7f2FYsabKOFj3enK+HQ+cBmTMbAG6aCesd1nLcFM1wtA9XHg0+rFIVA7+nomADjEbJ1R/Gd+xHBO79UnLqxDQ==", "base64");
55

benchmark/decryptLevelZero.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const Benchmark = require("benchmark");
2-
const recrypt = require("../native/index.node");
2+
const recrypt = require("../index.node");
33
//Randomly generated legit ED25519 keypair
44
const privateSigningKey = Buffer.from("O7f2FYsabKOFj3enK+HQ+cBmTMbAG6aCesd1nLcFM1wtA9XHg0+rFIVA7+nomADjEbJ1R/Gd+xHBO79UnLqxDQ==", "base64");
55

benchmark/deriveSymmetricKey.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const Benchmark = require("benchmark");
2-
const recrypt = require("../native/index.node");
2+
const recrypt = require("../index.node");
33

44
const api = new recrypt.Api256();
55

benchmark/encrypt.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const Benchmark = require("benchmark");
2-
const recrypt = require("../native/index.node");
2+
const recrypt = require("../index.node");
33

44
const privateSigningKey = Buffer.from("O7f2FYsabKOFj3enK+HQ+cBmTMbAG6aCesd1nLcFM1wtA9XHg0+rFIVA7+nomADjEbJ1R/Gd+xHBO79UnLqxDQ==", "base64");
55

benchmark/generateEd25519KeyPair.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const Benchmark = require("benchmark");
2-
const recrypt = require("../native/index.node");
2+
const recrypt = require("../index.node");
33

44
const api = new recrypt.Api256();
55

benchmark/generateKeyPair.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const Benchmark = require("benchmark");
2-
const recrypt = require("../native/index.node");
2+
const recrypt = require("../index.node");
33

44
const api = new recrypt.Api256();
55

benchmark/generatePlaintext.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const Benchmark = require("benchmark");
2-
const recrypt = require("../native/index.node");
2+
const recrypt = require("../index.node");
33

44
const api = new recrypt.Api256();
55

benchmark/generateTransformKey.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const Benchmark = require("benchmark");
2-
const recrypt = require("../native/index.node");
2+
const recrypt = require("../index.node");
33

44
const api = new recrypt.Api256();
55

benchmark/transformLevelOne.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const Benchmark = require("benchmark");
2-
const recrypt = require("../native/index.node");
2+
const recrypt = require("../index.node");
33
//Randomly generated legit ED25519 keypair
44
const privateSigningKey = Buffer.from("O7f2FYsabKOFj3enK+HQ+cBmTMbAG6aCesd1nLcFM1wtA9XHg0+rFIVA7+nomADjEbJ1R/Gd+xHBO79UnLqxDQ==", "base64");
55

benchmark/transformLevelTwo.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const Benchmark = require("benchmark");
2-
const recrypt = require("../native/index.node");
2+
const recrypt = require("../index.node");
33
//Randomly generated legit ED25519 keypair
44
const privateSigningKey = Buffer.from("O7f2FYsabKOFj3enK+HQ+cBmTMbAG6aCesd1nLcFM1wtA9XHg0+rFIVA7+nomADjEbJ1R/Gd+xHBO79UnLqxDQ==", "base64");
55

index.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
"use strict";
22

3-
// TODO: is this even going to resolve when distributed?
4-
// TODO: might want to introduce a TS build process and generate the index.d.ts
5-
const internal = require("./native/index.node");
3+
/**
4+
* WARNING!
5+
*
6+
* This file is the bridge between the generated Rust binary and the JavaScript interface users call into.
7+
*
8+
* This file is not generated. Any changes made in the Rust code will need to be propogated out here, either by adding
9+
* bare functions to the export declaration at the bottom, or by adding new methods to the Api256 class.
10+
*
11+
* The `index.d.ts` file is also manually maintained, add any new signatures to it.
12+
*/
13+
14+
const internal = require("./bin-package/index.node");
615

716
class Api256 {
817
constructor() {

package.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ironcorelabs/recrypt-node-binding",
3-
"version": "0.7.4-pre.22",
3+
"version": "0.8.0-pre.1",
44
"description": "Bindings to allow the recrypt-rs library to work via NodeJS.",
55
"repository": {
66
"type": "git",
@@ -9,7 +9,7 @@
99
"homepage": "https://ironcorelabs.com",
1010
"author": "IronCore Labs",
1111
"license": "AGPL-3.0-only",
12-
"main": "bin-package/index.node",
12+
"main": "index.js",
1313
"types": "index.d.ts",
1414
"engines": {
1515
"node": ">=12.0.0"
@@ -23,20 +23,20 @@
2323
"x64"
2424
],
2525
"scripts": {
26-
"compile": "neon build -r",
27-
"clean": "neon clean",
26+
"compile": "cargo-cp-artifact -a cdylib recrypt_node ./bin-package/index.node -- cargo build --release --message-format=json-render-diagnostics",
27+
"clean": "cargo clean && rm -rf dist && rm -rf bin-package && rm -rf build",
2828
"benchmark": "node benchmark/index.js",
29-
"test": "jest"
29+
"test": "jest --maxWorkers=50%"
3030
},
3131
"dependencies": {
3232
"@mapbox/node-pre-gyp": "^1.0.7"
3333
},
3434
"devDependencies": {
3535
"@types/node": "^16.11.11",
3636
"benchmark": "^2.1.4",
37+
"cargo-cp-artifact": "^0.1.6",
3738
"jest": "^27.4.0",
3839
"jest-extended": "^1.2.0",
39-
"neon-cli": "^0.9.1",
4040
"shelljs": "^0.8.4"
4141
},
4242
"prettier": {

publish.js

+3-12
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,22 @@ shell.cd(rootDirectory);
2727
const shouldPublish = process.argv.slice(2).indexOf("--publish") !== -1;
2828
const isPreRelease = process.argv.slice(2).indexOf("--prerelease") !== -1;
2929

30-
//Cleanup the previous build, if it exists
31-
shell.rm("-rf", "./dist");
32-
shell.rm("-rf", "./bin-package");
33-
shell.rm("-rf", "./build");
34-
3530
// Cleanup any previous Rust builds, update deps, and compile
3631
shell.exec("yarn install --ignore-scripts");
37-
shell.exec("yarn run clean");
38-
shell.pushd("./native");
39-
shell.popd();
40-
shell.exec("yarn run compile");
32+
shell.exec("yarn clean");
33+
shell.exec("yarn compile");
4134

4235
shell.exec("yarn test");
4336
shell.mkdir("./dist");
4437

45-
shell.cp(["README.md", "package.json", "index.d.ts", "LICENSE"], "./dist");
38+
shell.cp(["README.md", "package.json", "index.d.ts", "index.js", "LICENSE"], "./dist");
4639

4740
//Add a NPM install script to the package.json that we push to NPM so that when consumers pull it down it
4841
//runs the expected node-pre-gyp step.
4942
const npmPackageJson = require("./dist/package.json");
5043
npmPackageJson.scripts.install = "node-pre-gyp install";
5144
fs.writeFileSync("./dist/package.json", JSON.stringify(npmPackageJson, null, 2));
5245

53-
shell.mkdir("./bin-package");
54-
shell.cp("./native/index.node", "./bin-package");
5546
//Use a fully qualified path to pre-gyp binary for Windows support
5647
const cwd = shell.pwd().toString();
5748
shell.exec(`${cwd}/node_modules/node-pre-gyp/bin/node-pre-gyp package`);

native/src/api256.rs src/api256.rs

File renamed without changes.

native/src/lib.rs src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ fn main(mut cx: ModuleContext) -> NeonResult<()> {
1111
cx.export_function("transformKeyToBytes256", api256::transform_key_to_bytes_256)?;
1212
cx.export_function("addPrivateKeys", api256::add_private_keys)?;
1313
cx.export_function("subtractPrivateKeys", api256::subtract_private_keys)?;
14-
// cx.export_class::<api256::Api256>("Api256") TODO: get the class working
1514
// Api256 member functions
1615
cx.export_function("createApi256", api256::api256_create_recrypt_api_256)?;
1716
cx.export_function("generateKeyPair", api256::api256_generate_key_pair)?;

native/src/util.rs src/util.rs

+10-15
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub fn bytes_to_buffer<'a, T: Context<'a>>(
5252
) -> NeonResult<Handle<'a, JsBuffer>> {
5353
let mut buffer: Handle<JsBuffer> = cx.buffer(data.len() as u32)?;
5454
cx.borrow_mut(&mut buffer, |contents| {
55-
contents.as_mut_slice().copy_from_slice(&data)
55+
contents.as_mut_slice().copy_from_slice(data)
5656
});
5757
Ok(buffer)
5858
}
@@ -249,20 +249,15 @@ pub fn transform_blocks_to_js_object<'a, T: Context<'a>>(
249249
) -> NeonResult<Handle<'a, JsArray>> {
250250
let blocks_array: Handle<JsArray> = JsArray::new(cx, transform_blocks.len() as u32);
251251

252-
for i in 0..transform_blocks.len() {
252+
for (i, block_rs) in transform_blocks.iter().enumerate() {
253253
let block = cx.empty_object();
254254

255-
let public_key = public_key_to_js_object(cx, &transform_blocks[i].public_key())?;
256-
let encrypted_temp_key =
257-
bytes_to_buffer(cx, transform_blocks[i].encrypted_temp_key().bytes())?;
255+
let public_key = public_key_to_js_object(cx, block_rs.public_key())?;
256+
let encrypted_temp_key = bytes_to_buffer(cx, block_rs.encrypted_temp_key().bytes())?;
258257
let random_transform_public_key =
259-
public_key_to_js_object(cx, &transform_blocks[i].random_transform_public_key())?;
260-
let encrypted_random_transform_temp_key = bytes_to_buffer(
261-
cx,
262-
transform_blocks[i]
263-
.encrypted_random_transform_temp_key()
264-
.bytes(),
265-
)?;
258+
public_key_to_js_object(cx, block_rs.random_transform_public_key())?;
259+
let encrypted_random_transform_temp_key =
260+
bytes_to_buffer(cx, block_rs.encrypted_random_transform_temp_key().bytes())?;
266261

267262
block.set(cx, "publicKey", public_key)?;
268263
block.set(cx, "encryptedTempKey", encrypted_temp_key)?;
@@ -314,7 +309,8 @@ pub fn js_object_to_encrypted_value<'a, T: Context<'a>>(
314309
.downcast::<JsArray, _>(cx)
315310
.unwrap();
316311

317-
let encrypted_value = if transform_blocks.len(cx) > 0 {
312+
// create the encrypted value and return it
313+
if transform_blocks.len(cx) > 0 {
318314
EncryptedValue::TransformedValue {
319315
ephemeral_public_key: js_object_to_public_key(cx, emphemeral_public_key_obj),
320316
encrypted_message: EncryptedMessage::new(buffer_to_fixed_384_bytes(
@@ -347,8 +343,7 @@ pub fn js_object_to_encrypted_value<'a, T: Context<'a>>(
347343
)),
348344
signature: buffer_to_ed25519_signature(cx, signature_buffer),
349345
}
350-
};
351-
encrypted_value
346+
}
352347
}
353348

354349
/// Convert a Recrypt EncryptedValue into a JsObbject with expeted properties and bytes converted to Buffers.

0 commit comments

Comments
 (0)