1- import { Buffer } from 'node:buffer' ;
2- import { fieldFromRust , fieldToRust , fieldsFromRustFlat , fieldsToRustFlat } from './bindings/conversion-base.js' ;
3- import { Gate , OrInfinity , PolyComm , Wire , Field } from './bindings/kimchi-types.js' ;
41import { MlArray } from '../../lib/ml/base.js' ;
5- import { mapTuple } from './bindings/util.js' ;
62import type * as napiNamespace from '../compiled/node_bindings/plonk_wasm.cjs' ;
3+ import {
4+ fieldFromRust ,
5+ fieldToRust ,
6+ fieldsFromRustFlat ,
7+ fieldsToRustFlat ,
8+ } from './bindings/conversion-base.js' ;
9+ import { mapFromUintArray } from './bindings/conversion-core.js' ;
10+ import { Field , Gate , LookupTable , OrInfinity , PolyComm , Wire } from './bindings/kimchi-types.js' ;
11+ import { mapTuple } from './bindings/util.js' ;
712
813export { bindingsNapi } ;
914
@@ -17,7 +22,7 @@ type NapiClasses = {
1722 CommitmentCurve : typeof napiNamespace . WasmGVesta | typeof napiNamespace . WasmGPallas ;
1823 makeAffine : ( ) => NapiAffine ;
1924 PolyComm : napiNamespace . WasmFpPolyComm | napiNamespace . WasmFqPolyComm ;
20- }
25+ } ;
2126
2227function bindingsNapi ( napi : any ) {
2328 const fpCore = conversionCorePerField ( {
@@ -37,24 +42,30 @@ function bindingsNapi(napi: any) {
3742 wireToRust ( [ , row , col ] : Wire ) {
3843 return { row, col } ;
3944 } ,
45+ lookupTablesToRust ( [ , ...tables ] : MlArray < LookupTable > ) {
46+ return tables ;
47+ } ,
48+ runtimeTableCfgsToRust ( [ , ...tables ] : MlArray < Uint8Array > ) {
49+ return tables . map ( ( table ) => Array . from ( table ) ) ;
50+ } ,
4051 gateToRust ( gate : Gate ) : any {
41- const [ , typ , [ , ...wires ] , coeffs ] = gate ;
42- const mapped = mapTuple ( wires , ( wire ) => this . wireToRust ( wire ) ) ;
43- const nativeWires = {
44- w0 : mapped [ 0 ] ,
45- w1 : mapped [ 1 ] ,
46- w2 : mapped [ 2 ] ,
47- w3 : mapped [ 3 ] ,
48- w4 : mapped [ 4 ] ,
49- w5 : mapped [ 5 ] ,
50- w6 : mapped [ 6 ] ,
51- } as const ;
52- return {
53- typ,
54- wires : nativeWires ,
55- coeffs : Array . from ( fieldsToRustFlat ( coeffs ) ) ,
56- } ;
57- } ,
52+ const [ , typ , [ , ...wires ] , coeffs ] = gate ;
53+ const mapped = mapTuple ( wires , ( wire ) => this . wireToRust ( wire ) ) ;
54+ const nativeWires = {
55+ w0 : mapped [ 0 ] ,
56+ w1 : mapped [ 1 ] ,
57+ w2 : mapped [ 2 ] ,
58+ w3 : mapped [ 3 ] ,
59+ w4 : mapped [ 4 ] ,
60+ w5 : mapped [ 5 ] ,
61+ w6 : mapped [ 6 ] ,
62+ } as const ;
63+ return {
64+ typ,
65+ wires : nativeWires ,
66+ coeffs : Array . from ( fieldsToRustFlat ( coeffs ) ) ,
67+ } ;
68+ } ,
5869 } ;
5970
6071 return {
@@ -82,16 +93,24 @@ function conversionCorePerField({ makeAffine, PolyComm }: NapiClasses) {
8293 } ;
8394 const affineFromRust = ( pt : NapiAffine ) : OrInfinity => {
8495 if ( pt . infinity ) return 0 ;
96+ console . log ( 'pt' , pt ) ;
97+ console . log ( 'pt.x' , pt . x ) ;
98+ console . log ( 'pt.y' , pt . y ) ;
99+
85100 const xField = fieldFromRust ( pt . x ) ;
86101 const yField = fieldFromRust ( pt . y ) ;
87102 return [ 0 , [ 0 , xField , yField ] ] ;
88- } ;
103+ } ;
89104
90105 const pointToRust = ( point : OrInfinity ) : NapiAffine => affineToRust ( point ) ;
91106 const pointFromRust = ( point : NapiAffine ) : OrInfinity => affineFromRust ( point ) ;
92107
93- const pointsToRust = ( [ , ...points ] : MlArray < OrInfinity > ) : NapiAffine [ ] => points . map ( affineToRust ) ;
94- const pointsFromRust = ( points : NapiAffine [ ] ) : MlArray < OrInfinity > => [ 0 , ...points . map ( affineFromRust ) ] ;
108+ const pointsToRust = ( [ , ...points ] : MlArray < OrInfinity > ) : NapiAffine [ ] =>
109+ points . map ( affineToRust ) ;
110+ const pointsFromRust = ( points : NapiAffine [ ] ) : MlArray < OrInfinity > => [
111+ 0 ,
112+ ...points . map ( affineFromRust ) ,
113+ ] ;
95114
96115 const polyCommToRust = ( polyComm : PolyComm ) : NapiPolyComm => {
97116 const [ , camlElems ] = polyComm ;
@@ -100,10 +119,22 @@ function conversionCorePerField({ makeAffine, PolyComm }: NapiClasses) {
100119 return new PolyCommClass ( unshifted as unknown , undefined ) ;
101120 } ;
102121
103- const polyCommFromRust = ( polyComm : NapiPolyComm ) : PolyComm => {
122+ /* const polyCommFromRust = (polyComm: NapiPolyComm): PolyComm => {
123+ console.log('polyComm', polyComm);
104124 const rustUnshifted = asArrayLike<NapiAffine>(polyComm.unshifted, 'polyComm.unshifted');
125+ console.log('rustUnshifted', rustUnshifted);
105126 const mlUnshifted = rustUnshifted.map(affineFromRust);
106127 return [0, [0, ...mlUnshifted]];
128+ }; */
129+ const polyCommFromRust = ( polyComm : any ) : any => {
130+ let rustUnshifted = polyComm . unshifted ;
131+ console . log ( 'rustUnshifted' , rustUnshifted ) ;
132+ let mlUnshifted = mapFromUintArray ( rustUnshifted , ( ptr ) => {
133+ console . log ( 'ptr' , ptr ) ;
134+ /* return affineFromRust(wrap(ptr, CommitmentCurve));
135+ */
136+ } ) ;
137+ return [ 0 , [ 0 , ...mlUnshifted ] ] ;
107138 } ;
108139
109140 const polyCommsToRust = ( [ , ...comms ] : MlArray < PolyComm > ) : NapiPolyComm [ ] =>
0 commit comments