@@ -16,15 +16,19 @@ import { verifierIndexConversion } from './bindings/conversion-verifier-index.js
1616import { oraclesConversion } from './bindings/conversion-oracles.js' ;
1717import { jsEnvironment } from './bindings/env.js' ;
1818import { 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
2025import { conversionCore as conversionCoreNative } from './native/conversion-core.js';
2126import { fieldsFromRustFlat as fieldsFromRustFlatNative, fieldsToRustFlat as fieldsToRustFlatNative } from './native/conversion-base.js';
2227import { proofConversion as proofConversionNative } from './native/conversion-proof.js';
2328import { verifierIndexConversion as verifierIndexConversionNative } from './native/conversion-verifier-index.js';
2429import { 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
2933const 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
5057type 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+
5299function 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>;
75122type NativeConversion = ReturnType<typeof createNativeConversion>;
76123type RustConversion = WasmConversion | NativeConversion;
77124
78- function getRustConversion ( wasm : Wasm ) : RustConversion {
79- return createRustConversion ( wasm ) ;
80- }
81-
82125function 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-
106141type 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