Skip to content

Commit

Permalink
new pkg generated
Browse files Browse the repository at this point in the history
  • Loading branch information
luiz-lvj committed Oct 3, 2024
1 parent f09c3fe commit a969ddc
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 13 deletions.
8 changes: 4 additions & 4 deletions tools/npm/garaga_ts/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tools/npm/garaga_ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"devDependencies": {
"@rollup/plugin-typescript": "^11.1.6",
"@types/jest": "^29.5.13",
"@types/node": "^22.5.4",
"@types/node": "^22.7.4",
"jest": "^29.7.0",
"rollup": "^4.21.2",
"rollup-plugin-dts": "^6.1.1",
Expand Down
14 changes: 14 additions & 0 deletions tools/npm/garaga_ts/src/wasm/pkg/garaga_rs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,26 @@
* @returns {any[]}
*/
export function msm_calldata_builder(values: any[], scalars: any[], curve_id: number, include_digits_decomposition: boolean, include_points_and_scalars: boolean, serialize_as_pure_felt252_array: boolean, risc0_mode: boolean): any[];
/**
* @param {any} x_twisted
* @param {any} y_twisted
* @returns {any[]}
*/
export function to_weirstrass(x_twisted: any, y_twisted: any): any[];
/**
* @param {any} x_weirstrass
* @param {any} y_weirstrass
* @returns {any[]}
*/
export function to_twistededwards(x_weirstrass: any, y_weirstrass: any): any[];

export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;

export interface InitOutput {
readonly memory: WebAssembly.Memory;
readonly msm_calldata_builder: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => void;
readonly to_weirstrass: (a: number, b: number, c: number) => void;
readonly to_twistededwards: (a: number, b: number, c: number) => void;
readonly __wbindgen_malloc: (a: number, b: number) => number;
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
Expand Down
134 changes: 127 additions & 7 deletions tools/npm/garaga_ts/src/wasm/pkg/garaga_rs.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,71 @@ function getDataViewMemory0() {
return cachedDataViewMemory0;
}

function debugString(val) {
// primitive types
const type = typeof val;
if (type == 'number' || type == 'boolean' || val == null) {
return `${val}`;
}
if (type == 'string') {
return `"${val}"`;
}
if (type == 'symbol') {
const description = val.description;
if (description == null) {
return 'Symbol';
} else {
return `Symbol(${description})`;
}
}
if (type == 'function') {
const name = val.name;
if (typeof name == 'string' && name.length > 0) {
return `Function(${name})`;
} else {
return 'Function';
}
}
// objects
if (Array.isArray(val)) {
const length = val.length;
let debug = '[';
if (length > 0) {
debug += debugString(val[0]);
}
for(let i = 1; i < length; i++) {
debug += ', ' + debugString(val[i]);
}
debug += ']';
return debug;
}
// Test for built-in
const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
let className;
if (builtInMatches.length > 1) {
className = builtInMatches[1];
} else {
// Failed to match the standard '[object ClassName]'
return toString.call(val);
}
if (className == 'Object') {
// we're a user defined class or Object
// JSON.stringify avoids problems with cycles, and is generally much
// easier than looping through ownProperties of `val`.
try {
return 'Object(' + JSON.stringify(val) + ')';
} catch (_) {
return 'Object';
}
}
// errors
if (val instanceof Error) {
return `${val.name}: ${val.message}\n${val.stack}`;
}
// TODO we could test for more things here, like `Set`s and `Map`s.
return className;
}

function passArrayJsValueToWasm0(array, malloc) {
const ptr = malloc(array.length * 4, 4) >>> 0;
const mem = getDataViewMemory0();
Expand Down Expand Up @@ -168,6 +233,54 @@ export function msm_calldata_builder(values, scalars, curve_id, include_digits_d
}
}

/**
* @param {any} x_twisted
* @param {any} y_twisted
* @returns {any[]}
*/
export function to_weirstrass(x_twisted, y_twisted) {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.to_weirstrass(retptr, addHeapObject(x_twisted), addHeapObject(y_twisted));
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
if (r3) {
throw takeObject(r2);
}
var v1 = getArrayJsValueFromWasm0(r0, r1).slice();
wasm.__wbindgen_free(r0, r1 * 4, 4);
return v1;
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}

/**
* @param {any} x_weirstrass
* @param {any} y_weirstrass
* @returns {any[]}
*/
export function to_twistededwards(x_weirstrass, y_weirstrass) {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.to_twistededwards(retptr, addHeapObject(x_weirstrass), addHeapObject(y_weirstrass));
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
if (r3) {
throw takeObject(r2);
}
var v1 = getArrayJsValueFromWasm0(r0, r1).slice();
wasm.__wbindgen_free(r0, r1 * 4, 4);
return v1;
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
}
}

async function __wbg_load(module, imports) {
if (typeof Response === 'function' && module instanceof Response) {
if (typeof WebAssembly.instantiateStreaming === 'function') {
Expand Down Expand Up @@ -206,17 +319,13 @@ function __wbg_get_imports() {
const ret = getStringFromWasm0(arg0, arg1);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
takeObject(arg0);
};
imports.wbg.__wbindgen_bigint_from_str = function(arg0, arg1) {
const ret = BigInt(getStringFromWasm0(arg0, arg1));
return addHeapObject(ret);
};
imports.wbg.__wbindgen_add = function(arg0, arg1) {
const ret = getObject(arg0) + getObject(arg1);
return addHeapObject(ret);
};
imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
takeObject(arg0);
};
imports.wbg.__wbindgen_string_get = function(arg0, arg1) {
const obj = getObject(arg1);
const ret = typeof(obj) === 'string' ? obj : undefined;
Expand All @@ -225,6 +334,17 @@ function __wbg_get_imports() {
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
};
imports.wbg.__wbindgen_bigint_from_str = function(arg0, arg1) {
const ret = BigInt(getStringFromWasm0(arg0, arg1));
return addHeapObject(ret);
};
imports.wbg.__wbindgen_debug_string = function(arg0, arg1) {
const ret = debugString(getObject(arg1));
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len1 = WASM_VECTOR_LEN;
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
};

return imports;
}
Expand Down
2 changes: 1 addition & 1 deletion tools/npm/garaga_ts/src/wasm/pkg/garaga_rs_bg.wasm.js

Large diffs are not rendered by default.

0 comments on commit a969ddc

Please sign in to comment.