Skip to content

Commit 6f6e1b1

Browse files
committed
bindings: comment out conversion bundle
2 parents 29142ff + 59668c5 commit 6f6e1b1

File tree

2 files changed

+84
-17
lines changed

2 files changed

+84
-17
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { fieldsFromRustFlat, fieldsToRustFlat } from './bindings/conversion-base.js';
2+
3+
export { bindingsNapi };
4+
5+
function bindingsNapi(napi: any) {
6+
return {
7+
fp: {
8+
vectorToRust: (fields: any) => {
9+
console.log('values going in ', fields);
10+
let res = fieldsToRustFlat(fields);
11+
console.log('values going out ', res);
12+
return res;
13+
},
14+
vectorFromRust: fieldsFromRustFlat,
15+
},
16+
fq: {
17+
vectorToRust: (fields: any) => {
18+
console.log('values going in ', fields);
19+
let res = fieldsToRustFlat(fields);
20+
console.log('values going out ', res);
21+
return res;
22+
},
23+
vectorFromRust: (fieldBytes: any) => {
24+
console.log('values going in ', fieldBytes);
25+
let res = fieldsFromRustFlat(fieldBytes);
26+
console.log('values going out ', res);
27+
return res;
28+
},
29+
},
30+
};
31+
}

src/bindings/crypto/bindings.ts

Lines changed: 53 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,19 @@ import { verifierIndexConversion } from './bindings/conversion-verifier-index.js
1616
import { oraclesConversion } from './bindings/conversion-oracles.js';
1717
import { jsEnvironment } from './bindings/env.js';
1818
import { srs } from './bindings/srs.js';
19-
// native
19+
import { bindingsNapi } from './bindings-napi.js';
20+
21+
export { getRustConversion, RustConversion, Wasm, createNativeRustConversion };
22+
23+
24+
/* TODO: Uncomment in phase 2 of conversion layer
2025
import { conversionCore as conversionCoreNative } from './native/conversion-core.js';
2126
import { fieldsFromRustFlat as fieldsFromRustFlatNative, fieldsToRustFlat as fieldsToRustFlatNative } from './native/conversion-base.js';
2227
import { proofConversion as proofConversionNative } from './native/conversion-proof.js';
2328
import { verifierIndexConversion as verifierIndexConversionNative } from './native/conversion-verifier-index.js';
2429
import { oraclesConversion as oraclesConversionNative } from './native/conversion-oracles.js';
25-
import { srs as srsNative } from './native/srs.js';
2630
27-
export { getRustConversion, type RustConversion, type NativeConversion, type Wasm };
31+
export { getRustConversion, type RustConversion, type NativeConversion, type Wasm };*/
2832

2933
const tsBindings = {
3034
jsEnvironment,
@@ -38,17 +42,60 @@ const tsBindings = {
3842
...FpVectorBindings,
3943
...FqVectorBindings,
4044
rustConversion: createRustConversion,
45+
nativeRustConversion: createNativeRustConversion,
46+
/* TODO: Uncomment in phase 2 of conversion layer
4147
srs: (wasm: Wasm) => {
4248
const bundle = getConversionBundle(wasm);
4349
return bundle.srsFactory(wasm, bundle.conversion);
44-
},
50+
},*/
51+
srs: (wasm: Wasm) => srs(wasm, getRustConversion(wasm)),
4552
};
4653

4754
// this is put in a global variable so that mina/src/lib/crypto/kimchi_bindings/js/bindings.js finds it
4855
(globalThis as any).__snarkyTsBindings = tsBindings;
4956

5057
type Wasm = typeof wasmNamespace;
5158

59+
type RustConversion = ReturnType<typeof buildWasmConversion>;
60+
61+
function getRustConversion(wasm: Wasm): RustConversion {
62+
return createRustConversion(wasm);
63+
}
64+
65+
function createRustConversion(wasm: Wasm) {
66+
return buildWasmConversion(wasm);
67+
}
68+
69+
function buildWasmConversion(wasm: Wasm) {
70+
let core = conversionCore(wasm);
71+
let verifierIndex = verifierIndexConversion(wasm, core);
72+
let oracles = oraclesConversion(wasm);
73+
let proof = proofConversion(wasm, core);
74+
75+
return {
76+
fp: { ...core.fp, ...verifierIndex.fp, ...oracles.fp, ...proof.fp },
77+
fq: { ...core.fq, ...verifierIndex.fq, ...oracles.fq, ...proof.fq },
78+
fieldsToRustFlat,
79+
fieldsFromRustFlat,
80+
wireToRust: core.wireToRust,
81+
mapMlArrayToRustVector: core.mapMlArrayToRustVector,
82+
};
83+
}
84+
85+
function createNativeRustConversion(napi: any) {
86+
return bindingsNapi(napi);
87+
}
88+
89+
/* TODO: Uncomment in phase 2 of conversion layer
90+
91+
function shouldUseNativeConversion(wasm: Wasm): boolean {
92+
const marker = (wasm as any).__kimchi_use_native;
93+
const globalMarker =
94+
typeof globalThis !== 'undefined' &&
95+
(globalThis as any).__kimchi_use_native;
96+
return Boolean(marker || globalMarker);
97+
}
98+
5299
function createRustConversion(wasm: Wasm): RustConversion {
53100
return shouldUseNativeConversion(wasm)
54101
? createNativeConversion(wasm)
@@ -60,7 +107,7 @@ function createWasmConversion(wasm: Wasm) {
60107
const verifierIndex = verifierIndexConversion(wasm, core);
61108
const oracles = oraclesConversion(wasm);
62109
const proof = proofConversion(wasm, core);
63-
110+
64111
return {
65112
fp: { ...core.fp, ...verifierIndex.fp, ...oracles.fp, ...proof.fp },
66113
fq: { ...core.fq, ...verifierIndex.fq, ...oracles.fq, ...proof.fq },
@@ -75,10 +122,6 @@ type WasmConversion = ReturnType<typeof createWasmConversion>;
75122
type NativeConversion = ReturnType<typeof createNativeConversion>;
76123
type RustConversion = WasmConversion | NativeConversion;
77124
78-
function getRustConversion(wasm: Wasm): RustConversion {
79-
return createRustConversion(wasm);
80-
}
81-
82125
function createNativeConversion(wasm: Wasm) {
83126
const core = conversionCoreNative(wasm);
84127
const verifierIndex = verifierIndexConversionNative(wasm, core);
@@ -95,14 +138,6 @@ function createNativeConversion(wasm: Wasm) {
95138
};
96139
}
97140
98-
function shouldUseNativeConversion(wasm: Wasm): boolean {
99-
const marker = (wasm as any).__kimchi_use_native;
100-
const globalMarker =
101-
typeof globalThis !== 'undefined' &&
102-
(globalThis as any).__kimchi_use_native;
103-
return Boolean(marker || globalMarker);
104-
}
105-
106141
type ConversionBundle =
107142
| { conversion: WasmConversion; srsFactory: typeof srs }
108143
| { conversion: NativeConversion; srsFactory: typeof srsNative };
@@ -113,3 +148,4 @@ function getConversionBundle(wasm: Wasm): ConversionBundle {
113148
}
114149
return { conversion: createWasmConversion(wasm), srsFactory: srs };
115150
}
151+
*/

0 commit comments

Comments
 (0)