Skip to content

Commit

Permalink
feat: add node 18 support
Browse files Browse the repository at this point in the history
  • Loading branch information
mate-from-mattr committed Sep 17, 2023
1 parent 4880c0e commit 6140f72
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 63 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/any-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ jobs:
name: Build test
runs-on: ${{matrix.os}}
strategy:
fail-fast: false
matrix:
node-version: [14.x, 16.x]
node-version: [14.x, 16.x, 18.x]
os: [macos-latest, ubuntu-latest] # not include windows due to node-gyp bug
steps:
- uses: actions/checkout@v1
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/push-binary-dispatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
runs-on: ${{matrix.os}}
strategy:
matrix:
node-version: [14.x, 16.x]
node-version: [14.x, 16.x, 18.x]
os: [macos-latest]
steps:
- uses: actions/checkout@v2
Expand All @@ -44,7 +44,7 @@ jobs:
runs-on: ${{matrix.os}}
strategy:
matrix:
node-version: [14.x, 16.x]
node-version: [14.x, 16.x, 18.x]
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/push-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x, 16.x]
node-version: [14.x, 16.x, 18.x]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/push-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ${{matrix.os}}
strategy:
matrix:
node-version: [14.x, 16.x]
node-version: [14.x, 16.x, 18.x]
os: [macos-latest, ubuntu-latest] # not include windows due to node-gyp bug
steps:
- uses: actions/checkout@v2
Expand All @@ -35,7 +35,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x]
node-version: [18.x]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
Expand Down
23 changes: 8 additions & 15 deletions native/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions native/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ name = "node_bbs_signatures"
crate-type = ["cdylib"]

[build-dependencies]
neon-build = "0.8"
neon-build = "0.10.1"

[dependencies]
arrayref = "0.3"
bbs = "0.4.1"
bls_sigs_ref = "0.3"
ff-zeroize = "0.6"
hkdf = "0.8"
neon = "0.8"
neon = "0.10.1"
pairing-plus = "0.19"
rand = "0.7"
sha2 = "0.8"
Expand Down
14 changes: 7 additions & 7 deletions native/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ fn bbs_sign(mut cx: FunctionContext) -> JsResult<JsArrayBuffer> {
));

let pk_bytes = obj_field_to_slice!(&mut cx, js_obj, "publicKey");
let pk = PublicKey::from_bytes_compressed_form(pk_bytes.as_slice()).unwrap();
let pk = PublicKey::from_bytes_compressed_form(pk_bytes).unwrap();

if pk.validate().is_err() {
panic!("Invalid key");
Expand Down Expand Up @@ -334,7 +334,7 @@ fn bbs_verify(mut cx: FunctionContext) -> JsResult<JsBoolean> {
));

let pk_bytes = obj_field_to_slice!(&mut cx, js_obj, "publicKey");
let pk = PublicKey::from_bytes_compressed_form(pk_bytes.as_slice()).unwrap();
let pk = PublicKey::from_bytes_compressed_form(pk_bytes).unwrap();

if pk.validate().is_err() {
panic!("Invalid key");
Expand Down Expand Up @@ -419,7 +419,7 @@ fn extract_blinding_context(cx: &mut FunctionContext) -> Result<BlindingContext,
let js_obj = cx.argument::<JsObject>(0)?;

let pk_bytes = obj_field_to_slice!(cx, js_obj, "publicKey");
let public_key = PublicKey::from_bytes_compressed_form(pk_bytes.as_slice()).unwrap();
let public_key = PublicKey::from_bytes_compressed_form(pk_bytes).unwrap();

if public_key.validate().is_err() {
panic!("Invalid key");
Expand Down Expand Up @@ -490,7 +490,7 @@ struct BlindingContext {
fn bbs_verify_blind_signature_proof(mut cx: FunctionContext) -> JsResult<JsBoolean> {
let js_obj = cx.argument::<JsObject>(0)?;
let pk_bytes = obj_field_to_slice!(&mut cx, js_obj, "publicKey");
let public_key = PublicKey::from_bytes_compressed_form(pk_bytes.as_slice()).unwrap();
let public_key = PublicKey::from_bytes_compressed_form(pk_bytes).unwrap();
if public_key.validate().is_err() {
panic!("Invalid key");
}
Expand Down Expand Up @@ -590,7 +590,7 @@ fn extract_blind_signature_context(cx: &mut FunctionContext) -> Result<BlindSign
));

let pk_bytes = obj_field_to_slice!(cx, js_obj, "publicKey");
let public_key = PublicKey::from_bytes_compressed_form(pk_bytes.as_slice()).unwrap();
let public_key = PublicKey::from_bytes_compressed_form(pk_bytes).unwrap();
if public_key.validate().is_err() {
panic!("Invalid key");
}
Expand Down Expand Up @@ -722,7 +722,7 @@ fn extract_create_proof_context(cx: &mut FunctionContext) -> Result<(Vec<u8>, Cr
SIGNATURE_COMPRESSED_SIZE
));
let pk_bytes = obj_field_to_slice!(cx, js_obj, "publicKey");
let public_key = PublicKey::from_bytes_compressed_form(pk_bytes.as_slice()).unwrap();
let public_key = PublicKey::from_bytes_compressed_form(pk_bytes).unwrap();
if public_key.validate().is_err() {
panic!("Invalid key");
}
Expand Down Expand Up @@ -882,7 +882,7 @@ fn extract_verify_proof_context(cx: &mut FunctionContext, is_bls: bool) -> Resul
dpk.to_public_key(message_count).unwrap()
} else {
let pk_bytes = obj_field_to_slice!(cx, js_obj, "publicKey");
PublicKey::from_bytes_compressed_form(pk_bytes.as_slice()).unwrap()
PublicKey::from_bytes_compressed_form(pk_bytes).unwrap()
};
if public_key.validate().is_err() {
panic!("Invalid key");
Expand Down
41 changes: 19 additions & 22 deletions native/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,47 +41,44 @@ macro_rules! arg_to_fixed_array {

macro_rules! obj_field_to_slice {
($cx:expr, $obj:expr, $field:expr) => {{
cast_to_slice!($cx, $obj.get($cx, $field)?)
$obj.get::<JsArrayBuffer, _, _>($cx, $field)?
.borrow(&$cx.lock())
.as_slice()
.to_vec()
}};
}

macro_rules! obj_field_to_fixed_array {
($cx:expr, $obj:expr, $field:expr, $start:expr, $end:expr) => {{
let a = cast_to_slice!($cx, $obj.get($cx, $field)?);
if a.len() != $end {
let handle = $obj.get::<JsArrayBuffer, _, _>($cx, $field)?;
let array = handle.borrow(&$cx.lock()).as_slice();
if array.len() != $end {
panic!("Invalid length");
}
*array_ref![a, $start, $end]
*array_ref![array, $start, $end]
}};
}

macro_rules! obj_field_to_opt_slice {
($cx:expr, $obj:expr, $field:expr) => {{
match $obj.get($cx, $field)?.downcast::<JsArrayBuffer>().or_throw($cx) {
match $obj.get::<JsArrayBuffer, _, _>($cx, $field) {
Err(_) => None,
Ok(arg) => Some($cx.borrow(&arg, |d| d.as_slice::<u8>()).to_vec())
Ok(arg) => Some(arg.borrow(&$cx.lock()).as_slice().to_vec()),
}
}};
}

macro_rules! obj_field_to_vec {
($cx:expr, $obj:expr, $field: expr) => {{
let v: Vec<Handle<JsValue>> = $obj
.get($cx, $field)?
let v = $obj
.get::<JsValue, _, _>($cx, $field)?
.downcast::<JsArray>()
.or_throw($cx)?
.to_vec($cx)?;
v
}};
}

macro_rules! cast_to_slice {
($cx:expr, $obj:expr) => {{
let arg = $obj.downcast::<JsArrayBuffer>().or_throw($cx)?;
$cx.borrow(&arg, |d| d.as_slice::<u8>()).to_vec()
}};
}

macro_rules! cast_to_number {
($cx:expr, $obj:expr) => {
$obj.downcast::<JsNumber>()
Expand All @@ -98,18 +95,18 @@ macro_rules! handle_err {

macro_rules! obj_field_to_field_elem {
($cx:expr, $d:expr) => {{
let m = cast_to_slice!($cx, $d);
SignatureMessage::hash(m)
let handle = $d.downcast::<JsArrayBuffer>().or_throw($cx)?;

$cx.borrow(&handle, |data| {
let slice = data.as_slice();
SignatureMessage::hash(slice)
})
}};
}

macro_rules! get_message_count {
($cx:expr, $obj:expr, $field:expr) => {{
let message_count = $obj
.get($cx, $field)?
.downcast::<JsNumber>()
.unwrap_or($cx.number(-1))
.value();
let message_count: f64 = $obj.get::<JsNumber, _, _>($cx, $field)?.value();

if message_count < 0f64 {
panic!("Message count cannot be negative: {}", message_count);
Expand Down
3 changes: 2 additions & 1 deletion native/tests/vectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ extern crate bbs;

use bbs::prelude::*;
use std::collections::BTreeSet;
use std::convert::TryFrom;

/// Computed by calling
///
Expand Down Expand Up @@ -350,4 +351,4 @@ fn bitvector_to_revealed(data: &[u8]) -> BTreeSet<usize> {
scalar += remaining;
}
revealed_messages
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"devDependencies": {
"@commitlint/cli": "17.0.2",
"@commitlint/config-conventional": "17.0.2",
"@mathquis/node-pre-gyp-github": "1.0.1",
"@mathquis/node-pre-gyp-github": "1.0.2",
"@stablelib/base64": "1.0.0",
"@stablelib/benchmark": "1.0.0",
"@stablelib/random": "1.0.0",
Expand All @@ -79,7 +79,7 @@
"typescript": "4.3.3"
},
"dependencies": {
"@mapbox/node-pre-gyp": "1.0.9",
"@mapbox/node-pre-gyp": "1.0.11",
"neon-cli": "0.10.1"
},
"resolutions": {
Expand Down
16 changes: 8 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -706,10 +706,10 @@
"@jridgewell/resolve-uri" "^3.0.3"
"@jridgewell/sourcemap-codec" "^1.4.10"

"@mapbox/[email protected].9":
version "1.0.9"
resolved "https://registry.yarnpkg.com/@mapbox/node-pre-gyp/-/node-pre-gyp-1.0.9.tgz#09a8781a3a036151cdebbe8719d6f8b25d4058bc"
integrity sha512-aDF3S3rK9Q2gey/WAttUlISduDItz5BU3306M9Eyv6/oS40aMprnopshtlKTykxRNIBEZuRMaZAnbrQ4QtKGyw==
"@mapbox/[email protected].11":
version "1.0.11"
resolved "https://registry.yarnpkg.com/@mapbox/node-pre-gyp/-/node-pre-gyp-1.0.11.tgz#417db42b7f5323d79e93b34a6d7a2a12c0df43fa"
integrity sha512-Yhlar6v9WQgUp/He7BdgzOz8lqMQ8sU+jkCq7Wx8Myc5YFJLbEe7lgui/V7G1qB1DJykHSGwreceSaD60Y0PUQ==
dependencies:
detect-libc "^2.0.0"
https-proxy-agent "^5.0.0"
Expand All @@ -721,10 +721,10 @@
semver "^7.3.5"
tar "^6.1.11"

"@mathquis/[email protected].1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@mathquis/node-pre-gyp-github/-/node-pre-gyp-github-1.0.1.tgz#57429d98f8c1169cb6fe138939233c7cb34a6498"
integrity sha512-zdUnMiurUPOgV3F1ROcSsVDIshqzdBDEdHg+obVwlV5noswCUeCjg6j966OPO76RrDB0kwFo7yfYLeeHpWeN5w==
"@mathquis/[email protected].2":
version "1.0.2"
resolved "https://registry.yarnpkg.com/@mathquis/node-pre-gyp-github/-/node-pre-gyp-github-1.0.2.tgz#de777222705312c2b806645cbbe5bcb1af92c00d"
integrity sha512-N2Yb1pTR5hEJjnfDD97UJXLGnG7B+9DMBiHiEXQ4B49P33YJcnvyNnA8xHUvhGu9XaAOw9pMUvweWoFrPVKY8g==
dependencies:
"@octokit/rest" "^18.1.1"
commander "^7.1.0"
Expand Down

0 comments on commit 6140f72

Please sign in to comment.