Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion src/lib/crypto/kimchi_bindings/js/bindings/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,35 @@
// Provides: tsBindings
var tsBindings = globalThis.__snarkyTsBindings;

// Provides: usingNativeBackend
// Requires: plonk_wasm, globalThis
var usingNativeBackend = Boolean(
(typeof plonk_wasm === 'object' && plonk_wasm && plonk_wasm.__native_backend) ||
(typeof globalThis !== 'undefined' && globalThis.__native_backend)
);

// Provides: nativeConversionFactory
// Requires: tsBindings
var nativeConversionFactory =
typeof tsBindings.nativeRustConversion === 'function'
? tsBindings.nativeRustConversion
: undefined;

// Provides: nativeConversion
// Requires: tsBindings, plonk_wasm
var nativeConversion = nativeConversionFactory
? nativeConversionFactory(plonk_wasm)
: undefined;

// Provides: tsRustConversion
// Requires: tsBindings, plonk_wasm
var tsRustConversion = tsBindings.rustConversion(plonk_wasm);
var tsRustConversion = usingNativeBackend && nativeConversion
? nativeConversion
: tsBindings.rustConversion(plonk_wasm);

// Provides: tsNativeRustConversion
// Requires: tsBindings, plonk_wasm
var tsNativeRustConversion = nativeConversion || tsRustConversion;

// Provides: getTsBindings
// Requires: tsBindings
Expand Down
20 changes: 13 additions & 7 deletions src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ try {
// native not available, keep WASM
}

if (native) {
plonk_wasm.__native_backend = true;
if (typeof globalThis !== 'undefined') {
globalThis.__native_backend = true;
}
}

function snakeToCamel(name) {
return name.replace(/_([a-z])/g, function (_match, ch) {
return ch.toUpperCase();
Expand All @@ -26,11 +33,10 @@ function override(functionName) {
[
'caml_pasta_fp_poseidon_block_cipher', // Poseidon
'caml_pasta_fq_poseidon_block_cipher', // Poseidon
'WasmFpPolyComm', // PolyComm
'WasmFqPolyComm', // PolyComm
'WasmGPallas', // Group
'WasmGVesta', // Group
'WasmVecVecFp', // Vector
'WasmVecVecFq', // Vector
//'WasmFpPolyComm', // PolyComm
//'WasmFqPolyComm', // PolyComm
// 'WasmGPallas', // Group
//'WasmGVesta', // Group
// 'WasmVecVecFp', // Vector
//'WasmVecVecFq', // Vector
].forEach(override);