Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demp/rust ocaml data flow #2092

Closed
wants to merge 4 commits into from
Closed
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
8 changes: 8 additions & 0 deletions src/examples/data-flow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { OCamlobject, initializeBindings } from 'o1js';

await initializeBindings();

let rustValue = OCamlobject.runMeRust();
console.log(rustValue);

OCamlobject.runMe();
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export { TupleN } from './lib/util/types.js';
export type { ProvablePure } from './lib/provable/types/provable-intf.js';
export { Ledger, initializeBindings } from './snarky.js';
export { Ledger, initializeBindings, OCamlobject } from './snarky.js';
export { Field, Bool, Group, Scalar } from './lib/provable/wrapped.js';
export {
createForeignField,
Expand Down
6 changes: 6 additions & 0 deletions src/snarky.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export {
MlPublicKeyVar,
MlFeatureFlags,
areBindingsInitialized,
OCamlobject,
};

declare let areBindingsInitialized: boolean;
Expand All @@ -63,6 +64,11 @@ declare namespace Snarky {
type Proof = unknown;
}

declare const OCamlobject: {
runMe: () => void;
runMeRust: () => string;
};

/**
* Internal interface to snarky-ml
*
Expand Down
6 changes: 4 additions & 2 deletions src/snarky.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import './bindings/crypto/bindings.js';
import { wasm, withThreadPool } from './bindings/js/node/node-backend.js';

let Snarky, Ledger, Pickles, Test_;
let Snarky, Ledger, Pickles, Test_, OCamlobject;
let isInitialized = false;

async function initializeBindings() {
Expand All @@ -17,7 +17,8 @@ async function initializeBindings() {
ESM: snarky = (
await import('./bindings/compiled/_node_bindings/o1js_node.bc.cjs')
).default;
({ Snarky, Ledger, Pickles, Test: Test_ } = snarky);

({ Snarky, Ledger, Pickles, Test: Test_, OCamlobject } = snarky);
}

async function Test() {
Expand All @@ -29,6 +30,7 @@ export {
Snarky,
Ledger,
Pickles,
OCamlobject,
Test,
withThreadPool,
wasm,
Expand Down
5 changes: 3 additions & 2 deletions src/snarky.web.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import {
wasm,
} from './bindings/js/web/web-backend.js';

let Snarky, Ledger, Pickles, Test_;
let Snarky, Ledger, Pickles, Test_, OCamlobject;
let isInitialized = false;

async function initializeBindings() {
if (isInitialized) return;
isInitialized = true;

await init();
({ Snarky, Ledger, Pickles, Test: Test_ } = globalThis.__snarky);
({ Snarky, Ledger, Pickles, Test: Test_, OCamlobject } = globalThis.__snarky);
}

async function Test() {
Expand All @@ -27,6 +27,7 @@ export {
Pickles,
Test,
withThreadPool,
OCamlobject,
wasm,
initializeBindings,
isInitialized as areBindingsInitialized,
Expand Down