Skip to content

Commit 9a01178

Browse files
Bump neon to 0.10.1, fix M1 builds in CI
1 parent 865aeab commit 9a01178

File tree

6 files changed

+58
-117
lines changed

6 files changed

+58
-117
lines changed

.github/workflows/typescript-ci.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ jobs:
2929
target: x86_64-unknown-linux-gnu
3030
- os: windows-2019
3131
target: x86_64-pc-windows-msvc
32+
arch:
33+
- x64
3234
include:
3335
- system:
3436
os:
@@ -38,6 +40,7 @@ jobs:
3840
target: aarch64-apple-darwin
3941
node_version: 16
4042
rust_version: 1.56.0
43+
arch: arm64
4144
- system:
4245
os:
4346
- self-hosted
@@ -46,6 +49,7 @@ jobs:
4649
target: aarch64-apple-darwin
4750
node_version: 16
4851
rust_version: stable
52+
arch: arm64
4953
- system:
5054
os:
5155
- self-hosted
@@ -54,12 +58,14 @@ jobs:
5458
target: aarch64-apple-darwin
5559
node_version: 16
5660
rust_version: beta
61+
arch: arm64
5762
fail-fast: false
5863
steps:
5964
- uses: actions/checkout@v3
6065
- uses: actions/setup-node@v3
6166
with:
6267
node-version: ${{ matrix.node_version }}
68+
architecture: ${{ matrix.arch }}
6369
cache: yarn
6470
- uses: actions-rs/toolchain@v1
6571
with:

Cargo.lock

Lines changed: 20 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ name = "recrypt_node"
1010
crate-type = ["cdylib"]
1111

1212
[dependencies]
13-
neon = { version = "0.9", default-features = false, features = ["napi-4"] }
13+
neon = { version = "0.10", default-features = false, features = ["napi-4"] }
1414
recrypt = "0.13.1"
1515

1616
[profile.release]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ assert.equal(decryptedValue, plaintext);
9696

9797
## Local Development
9898

99-
In order to build the binary Node file for Recrypt, you'll need the dependencies specified on the [Neon Bindings site](https://guides.neon-bindings.com/getting-started/). Follow their getting started directions and install Rust and the Node Build Tools. The Neon CLI is already installed as a dependecy of this project so you don't have to install that as a global dependency.
99+
In order to build the binary Node file for Recrypt, you'll need the dependencies specified on the [Neon Bindings site](https://guides.neon-bindings.com/getting-started/). Follow their getting started directions and install Rust and the Node Build Tools. The Neon CLI is already installed as a dependency of this project so you don't have to install that as a global dependency.
100100

101101
Once all of those dependencies are installed, the following can be run.
102102

src/util.rs

Lines changed: 27 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use neon::types::buffer::TypedArray;
12
use neon::{prelude::*, types::JsBuffer};
23
use recrypt::api::{
34
AuthHash, Ed25519Signature, EncryptedMessage, EncryptedTempKey, EncryptedValue, HashedValue,
@@ -9,10 +10,9 @@ use recrypt::nonemptyvec::NonEmptyVec;
910
/// Create an `$n` byte fixed u8 array given the provided JsBuffer handle. Throws an error if the provided Buffer
1011
/// is not of the required length.
1112
macro_rules! buffer_to_fixed_bytes { ($($fn_name: ident, $n: expr); *) => {
12-
$(pub fn $fn_name<'a, T>(cx: &T, mut buffer: Handle<JsBuffer>, field_name: &str) -> [u8; $n]
13+
$(pub fn $fn_name<'a, T>(cx: &T, buffer: Handle<JsBuffer>, field_name: &str) -> [u8; $n]
1314
where T: Context<'a>{
14-
let guard = cx.lock();
15-
let slice = buffer.borrow_mut(&guard).as_slice::<u8>();
15+
let slice = buffer.as_slice(cx);
1616
if slice.len() != $n {
1717
panic!("Provided Buffer for '{}' is not of expected size of {} bytes. Instead got {} bytes.", field_name, $n, slice.len());
1818
}
@@ -36,24 +36,17 @@ macro_rules! buffer_to_signature { ($($fn_name: ident, $sig_type: expr, $ret_typ
3636
buffer_to_signature! {buffer_to_schnorr_signature, SchnorrSignature::new, SchnorrSignature; buffer_to_ed25519_signature, Ed25519Signature::new, Ed25519Signature}
3737

3838
/// Convert a JsBuffer handle of variable size into a vector
39-
pub fn buffer_to_variable_bytes<'a, T: Context<'a>>(
40-
cx: &T,
41-
mut buffer: Handle<JsBuffer>,
42-
) -> Vec<u8> {
43-
let guard = cx.lock();
44-
let slice = buffer.borrow_mut(&guard).as_slice::<u8>();
45-
slice.to_vec()
39+
pub fn buffer_to_variable_bytes<'a, T: Context<'a>>(cx: &T, buffer: Handle<JsBuffer>) -> Vec<u8> {
40+
buffer.as_slice(cx).to_vec()
4641
}
4742

4843
/// Copy the bytes from the provided u8 slice into the provided JS Buffer object
4944
pub fn bytes_to_buffer<'a, T: Context<'a>>(
5045
cx: &mut T,
5146
data: &[u8],
5247
) -> NeonResult<Handle<'a, JsBuffer>> {
53-
let mut buffer: Handle<JsBuffer> = cx.buffer(data.len() as u32)?;
54-
cx.borrow_mut(&mut buffer, |contents| {
55-
contents.as_mut_slice().copy_from_slice(data)
56-
});
48+
let mut buffer: Handle<JsBuffer> = cx.buffer(data.len() as usize)?;
49+
buffer.as_mut_slice(cx).copy_from_slice(data);
5750
Ok(buffer)
5851
}
5952

@@ -72,16 +65,8 @@ pub fn js_object_to_public_key<'a, T: Context<'a>>(
7265
cx: &mut T,
7366
object: Handle<JsObject>,
7467
) -> PublicKey {
75-
let x = object
76-
.get(cx, "x")
77-
.unwrap()
78-
.downcast::<JsBuffer, _>(cx)
79-
.unwrap();
80-
let y = object
81-
.get(cx, "y")
82-
.unwrap()
83-
.downcast::<JsBuffer, _>(cx)
84-
.unwrap();
68+
let x = object.get(cx, "x").unwrap();
69+
let y = object.get(cx, "y").unwrap();
8570

8671
PublicKey::new((
8772
buffer_to_fixed_32_bytes(cx, x, "publicKey.x"),
@@ -110,39 +95,15 @@ pub fn js_object_to_transform_key<'a, T: Context<'a>>(
11095
cx: &mut T,
11196
object: Handle<JsObject>,
11297
) -> TransformKey {
113-
let encrypted_temp_key_buffer = object
114-
.get(cx, "encryptedTempKey")
115-
.unwrap()
116-
.downcast::<JsBuffer, _>(cx)
117-
.unwrap();
118-
let emphemeral_public_key_obj = object
119-
.get(cx, "ephemeralPublicKey")
120-
.unwrap()
121-
.downcast::<JsObject, _>(cx)
122-
.unwrap();
123-
let hashed_temp_key_buffer = object
124-
.get(cx, "hashedTempKey")
125-
.unwrap()
126-
.downcast::<JsBuffer, _>(cx)
127-
.unwrap();
128-
let public_signing_key_buffer = object
129-
.get(cx, "publicSigningKey")
130-
.unwrap()
131-
.downcast::<JsBuffer, _>(cx)
132-
.unwrap();
133-
let signature_buffer = object
134-
.get(cx, "signature")
135-
.unwrap()
136-
.downcast::<JsBuffer, _>(cx)
137-
.unwrap();
138-
let to_public_key_obj = object
139-
.get(cx, "toPublicKey")
140-
.unwrap()
141-
.downcast::<JsObject, _>(cx)
142-
.unwrap();
98+
let encrypted_temp_key_buffer = object.get(cx, "encryptedTempKey").unwrap();
99+
let ephemeral_public_key_obj = object.get(cx, "ephemeralPublicKey").unwrap();
100+
let hashed_temp_key_buffer = object.get(cx, "hashedTempKey").unwrap();
101+
let public_signing_key_buffer = object.get(cx, "publicSigningKey").unwrap();
102+
let signature_buffer = object.get(cx, "signature").unwrap();
103+
let to_public_key_obj = object.get(cx, "toPublicKey").unwrap();
143104

144105
TransformKey::new(
145-
js_object_to_public_key(cx, emphemeral_public_key_obj),
106+
js_object_to_public_key(cx, ephemeral_public_key_obj),
146107
js_object_to_public_key(cx, to_public_key_obj),
147108
EncryptedTempKey::new(buffer_to_fixed_384_bytes(
148109
cx,
@@ -200,25 +161,12 @@ pub fn js_object_to_transform_blocks<'a, T: Context<'a>>(
200161
.iter()
201162
.map(|block| {
202163
let block_obj = block.downcast::<JsObject, _>(cx).unwrap();
203-
let public_key = block_obj
204-
.get(cx, "publicKey")
205-
.unwrap()
206-
.downcast::<JsObject, _>(cx)
207-
.unwrap();
208-
let encrypted_temp_key = block_obj
209-
.get(cx, "encryptedTempKey")
210-
.unwrap()
211-
.downcast::<JsBuffer, _>(cx)
212-
.unwrap();
213-
let random_transform_public_key = block_obj
214-
.get(cx, "randomTransformPublicKey")
215-
.unwrap()
216-
.downcast::<JsObject, _>(cx)
217-
.unwrap();
164+
let public_key = block_obj.get(cx, "publicKey").unwrap();
165+
let encrypted_temp_key = block_obj.get(cx, "encryptedTempKey").unwrap();
166+
let random_transform_public_key =
167+
block_obj.get(cx, "randomTransformPublicKey").unwrap();
218168
let random_transform_encrypted_temp_key = block_obj
219169
.get(cx, "randomTransformEncryptedTempKey")
220-
.unwrap()
221-
.downcast::<JsBuffer, _>(cx)
222170
.unwrap();
223171

224172
TransformBlock::new(
@@ -279,35 +227,17 @@ pub fn js_object_to_encrypted_value<'a, T: Context<'a>>(
279227
object: Handle<JsObject>,
280228
) -> EncryptedValue {
281229
let emphemeral_public_key_obj = object
282-
.get(cx, "ephemeralPublicKey")
283-
.unwrap()
284-
.downcast::<JsObject, _>(cx)
230+
.get::<JsObject, _, _>(cx, "ephemeralPublicKey")
285231
.unwrap();
286232
let encrypted_message_buffer = object
287-
.get(cx, "encryptedMessage")
288-
.unwrap()
289-
.downcast::<JsBuffer, _>(cx)
290-
.unwrap();
291-
let auth_hash_buffer = object
292-
.get(cx, "authHash")
293-
.unwrap()
294-
.downcast::<JsBuffer, _>(cx)
233+
.get::<JsBuffer, _, _>(cx, "encryptedMessage")
295234
.unwrap();
235+
let auth_hash_buffer = object.get::<JsBuffer, _, _>(cx, "authHash").unwrap();
296236
let public_signing_key_buffer = object
297-
.get(cx, "publicSigningKey")
298-
.unwrap()
299-
.downcast::<JsBuffer, _>(cx)
300-
.unwrap();
301-
let signature_buffer = object
302-
.get(cx, "signature")
303-
.unwrap()
304-
.downcast::<JsBuffer, _>(cx)
305-
.unwrap();
306-
let transform_blocks = object
307-
.get(cx, "transformBlocks")
308-
.unwrap()
309-
.downcast::<JsArray, _>(cx)
237+
.get::<JsBuffer, _, _>(cx, "publicSigningKey")
310238
.unwrap();
239+
let signature_buffer = object.get::<JsBuffer, _, _>(cx, "signature").unwrap();
240+
let transform_blocks = object.get::<JsArray, _, _>(cx, "transformBlocks").unwrap();
311241

312242
// create the encrypted value and return it
313243
if transform_blocks.len(cx) > 0 {
@@ -346,7 +276,7 @@ pub fn js_object_to_encrypted_value<'a, T: Context<'a>>(
346276
}
347277
}
348278

349-
/// Convert a Recrypt EncryptedValue into a JsObbject with expeted properties and bytes converted to Buffers.
279+
/// Convert a Recrypt EncryptedValue into a JsObject with expected properties and bytes converted to Buffers.
350280
pub fn encrypted_value_to_js_object<'a, T: Context<'a>>(
351281
cx: &mut T,
352282
encrypted_value: EncryptedValue,

yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -862,9 +862,9 @@ camelcase@^6.2.0:
862862
integrity sha512-tVI4q5jjFV5CavAU8DXfza/TJcZutVKo/5Foskmsqcm0MsL91moHvwiGNnqaa2o6PF/7yT5ikDRcVcl8Rj6LCA==
863863

864864
caniuse-lite@^1.0.30001280:
865-
version "1.0.30001283"
866-
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001283.tgz#8573685bdae4d733ef18f78d44ba0ca5fe9e896b"
867-
integrity sha512-9RoKo841j1GQFSJz/nCXOj0sD7tHBtlowjYlrqIUS812x9/emfBLBt6IyMz1zIaYc/eRL8Cs6HPUVi2Hzq4sIg==
865+
version "1.0.30001355"
866+
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001355.tgz"
867+
integrity sha512-Sd6pjJHF27LzCB7pT7qs+kuX2ndurzCzkpJl6Qct7LPSZ9jn0bkOA8mdgMgmqnQAWLVOOGjLpc+66V57eLtb1g==
868868

869869
cargo-cp-artifact@^0.1.6:
870870
version "0.1.6"

0 commit comments

Comments
 (0)