Skip to content

Commit 7bcf6b4

Browse files
committed
backend: update override to account for snake/caml format in wasm vs napi
1 parent 16db348 commit 7bcf6b4

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

src/lib/crypto/kimchi_bindings/js/native/build.sh

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4-
CURRENT_DIRECTORY=$(pwd)
5-
PROOF_SYSTEMS_ROOT=$(cd ../../../proof-systems && pwd)
4+
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
5+
CURRENT_DIRECTORY="${SCRIPT_DIR}"
6+
PROOF_SYSTEMS_ROOT=$(cd "${SCRIPT_DIR}/../../../proof-systems" && pwd)
7+
PLONK_NAPI_ROOT="${PROOF_SYSTEMS_ROOT}/plonk-napi"
68

7-
cargo build \
8-
--manifest-path "${PROOF_SYSTEMS_ROOT}/Cargo.toml" \
9-
--release \
10-
-p plonk-napi
9+
TARGET_ROOT="${CARGO_TARGET_DIR:-"${PROOF_SYSTEMS_ROOT}/target"}"
10+
export CARGO_TARGET_DIR="${TARGET_ROOT}"
1111

12-
TARGET_ROOT=${CARGO_TARGET_DIR:-"${PROOF_SYSTEMS_ROOT}/target"}
12+
cargo build \
13+
--manifest-path "${PLONK_NAPI_ROOT}/Cargo.toml" \
14+
--release
1315

1416
case "$(uname -s)" in
1517
Darwin*) LIB_NAME="libplonk_napi.dylib" ;;
Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
11
// Provides: plonk_wasm
22
var plonk_wasm = require('./plonk_wasm.js');
33
var native = null;
4-
try {
5-
native = require('../native/plonk_napi.node');
4+
try {
5+
native = require('../native/plonk_napi.node');
66
} catch (e) {
7-
// native not available, keep WASM
7+
// native not available, keep WASM
88
}
99

10-
// Overwrite only the functions that are already available in native
11-
if (native && native.caml_pasta_fp_poseidon_block_cipher) {
12-
plonk_wasm.caml_pasta_fp_poseidon_block_cipher = native.caml_pasta_fp_poseidon_block_cipher;
10+
function snakeToCamel(name) {
11+
return name.replace(/_([a-z])/g, function (_match, ch) {
12+
return ch.toUpperCase();
13+
});
1314
}
14-
if (native && native.caml_pasta_fq_poseidon_block_cipher) {
15-
plonk_wasm.caml_pasta_fq_poseidon_block_cipher = native.caml_pasta_fq_poseidon_block_cipher;
15+
16+
function override(functionName) {
17+
if (!native) return;
18+
var camel = snakeToCamel(functionName);
19+
var impl = native[functionName] || native[camel];
20+
if (typeof impl === 'function') {
21+
plonk_wasm[functionName] = impl;
22+
}
1623
}
24+
25+
// Overwrite only the functions that are already available in native
26+
override('caml_pasta_fp_poseidon_block_cipher');
27+
override('caml_pasta_fq_poseidon_block_cipher');

0 commit comments

Comments
 (0)