diff --git a/create-aleo-app/template-node/_gitignore b/create-aleo-app/template-node/_gitignore new file mode 100644 index 000000000..a547bf36d --- /dev/null +++ b/create-aleo-app/template-node/_gitignore @@ -0,0 +1,24 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +node_modules +dist +dist-ssr +*.local + +# Editor directories and files +.vscode/* +!.vscode/extensions.json +.idea +.DS_Store +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? diff --git a/create-aleo-app/template-node/index.js b/create-aleo-app/template-node/index.js new file mode 100644 index 000000000..408e3daaa --- /dev/null +++ b/create-aleo-app/template-node/index.js @@ -0,0 +1,34 @@ +import {Account, initThreadPool, PrivateKey, ProgramManager,} from "@aleohq/sdk"; + +await initThreadPool(10); + +const hello_hello_program = + "program hello_hello.aleo;\n" + + "\n" + + "function hello:\n" + + " input r0 as u32.public;\n" + + " input r1 as u32.private;\n" + + " add r0 r1 into r2;\n" + + " output r2 as u32.private;\n"; + +async function localProgramExecution(program, aleoFunction, inputs) { + const programManager = new ProgramManager(); + + // Create a temporary account for the execution of the program + const account = new Account(); + programManager.setAccount(account); + + const executionResponse = await programManager.executeOffline( + hello_hello_program, + "hello", + ["5u32", "5u32"], + false, + ); + return executionResponse.getOutputs(); +} + +const start = Date.now(); +console.log("Starting execute!"); +const result = await localProgramExecution(); +console.log(result); +console.log("Execute finished!", Date.now() - start); \ No newline at end of file diff --git a/create-aleo-app/template-node/package.json b/create-aleo-app/template-node/package.json new file mode 100644 index 000000000..6395ddffa --- /dev/null +++ b/create-aleo-app/template-node/package.json @@ -0,0 +1,12 @@ +{ + "name": "node-starter", + "private": true, + "version": "0.0.0", + "type": "module", + "scripts": { + "start": "node index.js" + }, + "dependencies": { + "@aleohq/sdk": "^0.5.10" + } +} diff --git a/create-aleo-app/template-vanilla/package.json b/create-aleo-app/template-vanilla/package.json index 9dc145b60..09a1c60bb 100644 --- a/create-aleo-app/template-vanilla/package.json +++ b/create-aleo-app/template-vanilla/package.json @@ -13,6 +13,7 @@ }, "devDependencies": { "@aleohq/sdk": "^0.5.10", + "tslib": "^2.6.2", "vite": "^4.4.5" } } diff --git a/sdk/package.json b/sdk/package.json index 4a7cc1d06..3e02119dc 100644 --- a/sdk/package.json +++ b/sdk/package.json @@ -6,18 +6,23 @@ "The Aleo Team " ], "license": "GPL-3.0", - "main": "./dist/index.js", - "browser": "./dist/index.js", - "types": "./dist/index.d.ts", "type": "module", + "main": "./dist/node.js", + "browser": "./dist/index.js", + "exports": { + ".": { + "node": "./dist/node.js", + "default": "./dist/index.js" + } + }, "files": [ "dist", "LICENSE", "README.md" ], "scripts": { - "build": "rollup -c rollup.config.node.js", - "build:browser": "rollup -c rollup.config.browser.js", + "build": "rimraf dist && rollup -c rollup.config.js", + "prepublish": "npm run build", "clear_jest": "jest --clearCache", "dev": "tsc --watch", "test": "jest --config jest-config.json", @@ -38,27 +43,30 @@ }, "homepage": "https://github.com/AleoHQ/sdk#readme", "dependencies": { - "@aleohq/nodejs": "0.5.10", - "@aleohq/wasm": "0.5.10", + "@aleohq/wasm": "^0.6.0", "axios": "^1.1.3", "comlink": "^4.4.1", "jsdoc": "^3.6.11", - "unfetch": "^5.0.0" + "mime": "^3.0.0", + "sync-request": "^6.1.0" }, "devDependencies": { "@types/jest": "^29.4.0", + "@types/mime": "^3.0.1", "@typescript-eslint/eslint-plugin": "^5.41.0", "@typescript-eslint/parser": "^5.41.0", "better-docs": "^2.7.2", "clean-jsdoc-theme": "^4.1.8", + "cpr": "^3.0.1", "eslint": "^8.26.0", "eslint-config-prettier": "^8.5.0", "eslint-plugin-import": "^2.26.0", "jest": "^29.4.2", "prettier": "2.7.1", + "rimraf": "^5.0.1", "rollup": "^3.27.2", - "rollup-plugin-typescript2": "^0.35.0", + "rollup-plugin-typescript2": "^0.36.0", "ts-jest": "^29.0.5", - "typescript": "^4.8.4" + "typescript": "^5.2.2" } } diff --git a/sdk/rollup.config.browser.js b/sdk/rollup.config.browser.js deleted file mode 100644 index 22767c056..000000000 --- a/sdk/rollup.config.browser.js +++ /dev/null @@ -1,21 +0,0 @@ -import typescript from "rollup-plugin-typescript2"; - -const browserConfig = { - input: { - index: "./src/index.ts", - worker: "./src/worker.ts", - }, - output: { - dir: `dist`, - format: "es", - sourcemap: true, - }, - plugins: [ - typescript({ - tsconfig: "tsconfig.json", - clean: true, - }), - ], -}; - -export default [browserConfig]; diff --git a/sdk/rollup.config.js b/sdk/rollup.config.js new file mode 100644 index 000000000..d7d5e7582 --- /dev/null +++ b/sdk/rollup.config.js @@ -0,0 +1,34 @@ +import typescript from "rollup-plugin-typescript2"; + +export default { + input: { + index: "./src/index.ts", + thread: "./src/thread.ts", + worker: "./src/worker.ts", + node: "./src/node.ts", + "node-polyfill": "./src/node-polyfill.ts", + }, + output: { + dir: `dist`, + format: "es", + sourcemap: true, + }, + external: [ + "node:worker_threads", + "node:os", + "node:fs", + "node:crypto", + "mime/lite.js", + "sync-request", + "axios", + "comlink", + "@aleohq/wasm", + "@aleohq/wasm/worker.js", + ], + plugins: [ + typescript({ + tsconfig: "tsconfig.json", + clean: true, + }), + ], +}; diff --git a/sdk/rollup.config.node.js b/sdk/rollup.config.node.js deleted file mode 100644 index ddc84bfcd..000000000 --- a/sdk/rollup.config.node.js +++ /dev/null @@ -1,21 +0,0 @@ -import typescript from "rollup-plugin-typescript2"; - -const nodeConfig = { - input: { - index: "./src/index.ts", - }, - output: { - dir: `dist`, - format: "cjs", - sourcemap: true, - }, - plugins: [ - typescript({ - tsconfig: "tsconfig.json", - clean: true, - }), - ], -}; - - -export default [nodeConfig]; diff --git a/sdk/src/account.ts b/sdk/src/account.ts index 619808ca6..13b57099c 100644 --- a/sdk/src/account.ts +++ b/sdk/src/account.ts @@ -5,7 +5,7 @@ import { ViewKey, PrivateKeyCiphertext, RecordCiphertext, -} from "."; +} from "./index"; interface AccountParam { privateKey?: string; diff --git a/sdk/src/browser.ts b/sdk/src/browser.ts deleted file mode 100644 index 3833410ec..000000000 --- a/sdk/src/browser.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { ProgramManager } from "./program-manager"; -import init from "@aleohq/wasm"; -/** - * Initialize Aleo WebAssembly into the browser. The SDK requires its Wasm Instance to be initialized before operating - * so this function must be called before any other SDK functions are called. - */ -async function initializeWasm() { - return await init(); -} -import { createAleoWorker } from "./managed-worker"; -import { - Address, - ExecutionResponse, - PrivateKey, - PrivateKeyCiphertext, - Program, - ProvingKey, - RecordCiphertext, - RecordPlaintext, - ProgramManager as ProgramManagerBase, - Signature, - Transaction as WasmTransaction, - ViewKey, - VerifyingKey, - initThreadPool, - verifyFunctionExecution, -} from "@aleohq/wasm"; -export { - Address, - ExecutionResponse, - PrivateKey, - PrivateKeyCiphertext, - Program, - ProgramManager, - ProgramManagerBase, - ProvingKey, - RecordCiphertext, - RecordPlaintext, - Signature, - VerifyingKey, - ViewKey, - WasmTransaction, - initThreadPool, - initializeWasm, - verifyFunctionExecution, - createAleoWorker, -}; diff --git a/sdk/src/function-key-provider.ts b/sdk/src/function-key-provider.ts index c55a82636..a9811eece 100644 --- a/sdk/src/function-key-provider.ts +++ b/sdk/src/function-key-provider.ts @@ -1,4 +1,4 @@ -import { ProvingKey, VerifyingKey, CREDITS_PROGRAM_KEYS, KEY_STORE, PRIVATE_TRANSFER, PRIVATE_TO_PUBLIC_TRANSFER, PUBLIC_TRANSFER, PUBLIC_TO_PRIVATE_TRANSFER} from "."; +import { ProvingKey, VerifyingKey, CREDITS_PROGRAM_KEYS, KEY_STORE, PRIVATE_TRANSFER, PRIVATE_TO_PUBLIC_TRANSFER, PUBLIC_TRANSFER, PUBLIC_TO_PRIVATE_TRANSFER} from "./index"; import axios from 'axios'; type FunctionKeyPair = [ProvingKey, VerifyingKey]; diff --git a/sdk/src/index.ts b/sdk/src/index.ts index 88f3833d1..e7a9dce69 100644 --- a/sdk/src/index.ts +++ b/sdk/src/index.ts @@ -121,6 +121,49 @@ import { RecordSearchParams, } from "./record-provider"; +import { initThreadPool as wasmInitThreadPool } from "@aleohq/wasm"; + + +// @TODO: This function is no longer needed, remove it. +async function initializeWasm() { + console.warn("initializeWasm is deprecated, you no longer need to use it"); +} + +/** + * Initializes a thread pool of Workers. This enables multi-threading, which significantly improves performance. + */ +async function initThreadPool(threads: number) { + await wasmInitThreadPool(new URL("thread.js", import.meta.url), threads); +} + + +export { createAleoWorker } from "./managed-worker"; + +export { ProgramManager } from "./program-manager"; + +export { + PrivateKey, + ViewKey, + Address, + Private, + PrivateKeyCiphertext, + RecordCiphertext, + Signature, + ProvingKey, + VerifyingKey, + Program, + RecordPlaintext, + Transaction as WasmTransaction, + ExecutionResponse, + ProgramManager as ProgramManagerBase, + verifyFunctionExecution, +} from "@aleohq/wasm"; + +export { + initializeWasm, + initThreadPool, +}; + export { Account, AleoKeyProvider, @@ -150,10 +193,4 @@ export { PUBLIC_TO_PRIVATE_TRANSFER, VALID_TRANSFER_TYPES, logAndThrow, -}; - -// If using the SDK in a browser context, uncomment this line and run `npm run build:browser` -// export * from './browser'; - -// The following imports and exports are for a NodeJS context - if using the SDK in a browser context, delete or comment out this line -export * from './node'; +}; \ No newline at end of file diff --git a/sdk/src/network-client.ts b/sdk/src/network-client.ts index 9768af21d..49f0eac70 100644 --- a/sdk/src/network-client.ts +++ b/sdk/src/network-client.ts @@ -10,7 +10,7 @@ import { Transaction, Transition, logAndThrow -} from "."; +} from "./index"; type ProgramImports = { [key: string]: string | Program }; @@ -617,4 +617,4 @@ class AleoNetworkClient { } } -export { AleoNetworkClient, ProgramImports } \ No newline at end of file +export { AleoNetworkClient, ProgramImports } diff --git a/sdk/src/node-polyfill.ts b/sdk/src/node-polyfill.ts new file mode 100644 index 000000000..516099778 --- /dev/null +++ b/sdk/src/node-polyfill.ts @@ -0,0 +1,8 @@ +import "./polyfill/crypto"; +import "./polyfill/fetch"; +import "./polyfill/xmlhttprequest"; +import "./polyfill/worker"; + +if (!globalThis.self) { + (globalThis as any).self = globalThis; +} diff --git a/sdk/src/node.ts b/sdk/src/node.ts index c3b0d6894..6aadbc294 100644 --- a/sdk/src/node.ts +++ b/sdk/src/node.ts @@ -1,34 +1,2 @@ -import { CachedKeyPair } from "./function-key-provider"; - -export { CachedKeyPair }; - -import { - Address, - ExecutionResponse, - PrivateKey, - PrivateKeyCiphertext, - Program, - ProvingKey, - RecordCiphertext, - RecordPlaintext, - Signature, - Transaction as WasmTransaction, - ViewKey, - VerifyingKey, - verifyFunctionExecution, -} from "@aleohq/nodejs"; -export { - Address, - ExecutionResponse, - PrivateKey, - PrivateKeyCiphertext, - Program, - ProvingKey, - RecordCiphertext, - RecordPlaintext, - Signature, - VerifyingKey, - ViewKey, - WasmTransaction, - verifyFunctionExecution, -}; +import "./node-polyfill"; +export * from "./index"; diff --git a/sdk/src/polyfill/crypto.ts b/sdk/src/polyfill/crypto.ts new file mode 100644 index 000000000..e6582badb --- /dev/null +++ b/sdk/src/polyfill/crypto.ts @@ -0,0 +1,5 @@ +import { webcrypto } from "node:crypto"; + +if ((globalThis as any).crypto == null) { + (globalThis as any).crypto = webcrypto; +} diff --git a/sdk/src/polyfill/fetch.ts b/sdk/src/polyfill/fetch.ts new file mode 100644 index 000000000..3c199c3c5 --- /dev/null +++ b/sdk/src/polyfill/fetch.ts @@ -0,0 +1,33 @@ +import * as $fs from "node:fs"; +import $mime from "mime/lite.js"; + + +const oldFetch = globalThis.fetch; + +// We always polyfill fetch because Node's fetch doesn't support file URLs. +globalThis.fetch = async function (resource: URL | RequestInfo, options: RequestInit | undefined): Promise { + const request = new Request(resource, options); + + const url = new URL(request.url); + + if (url.protocol === "file:") { + const readStream = $fs.createReadStream(url); + + const headers: HeadersInit = {}; + + const type = $mime.getType(url.pathname); + + if (type) { + headers["Content-Type"] = type; + } + + return new Response(readStream as any, { + status: 200, + statusText: "OK", + headers, + }); + + } else { + return await oldFetch(request); + } +}; diff --git a/sdk/src/polyfill/worker.ts b/sdk/src/polyfill/worker.ts new file mode 100644 index 000000000..201078508 --- /dev/null +++ b/sdk/src/polyfill/worker.ts @@ -0,0 +1,210 @@ +function patch($worker: typeof import("node:worker_threads"), $os: typeof import("node:os")) { + // This is technically not a part of the Worker polyfill, + // but Workers are used for multi-threading, so this is often + // needed when writing Worker code. + if (globalThis.navigator == null) { + globalThis.navigator = { + hardwareConcurrency: $os.cpus().length, + } as Navigator; + } + + globalThis.Worker = class Worker extends EventTarget { + private _worker: import("node:worker_threads").Worker; + + constructor(url: string | URL, options?: WorkerOptions | undefined) { + super(); + + if (url instanceof URL) { + if (url.protocol !== "file:") { + throw new Error("Worker only supports file: URLs"); + } + + url = url.href; + + } else { + throw new Error("Filepaths are unreliable, use `new URL(\"...\", import.meta.url)` instead."); + } + + if (!options || options.type !== "module") { + throw new Error("Workers must use \`type: \"module\"\`"); + } + + // This uses some funky stuff like `patch.toString()`. + // + // This is needed so that it can synchronously run the polyfill code + // inside of the worker. + // + // It can't use `require` because the file doesn't have a `.cjs` file extension. + // + // It can't use `import` because that's asynchronous, and the file path + // might be different if using a bundler. + const code = ` + ${patch.toString()} + + // Inject the polyfill into the worker + patch(require("node:worker_threads"), require("node:os")); + + const { workerData } = require("node:worker_threads"); + + // This actually loads and runs the worker file + import(workerData.url) + .catch((e) => { + // TODO maybe it should send a message to the parent? + console.error(e.stack); + }); + `; + + this._worker = new $worker.Worker(code, { + eval: true, + workerData: { + url, + }, + }); + + this._worker.on("message", (data) => { + this.dispatchEvent(new MessageEvent("message", { data })); + }); + + this._worker.on("messageerror", (error) => { + throw new Error("UNIMPLEMENTED"); + }); + + this._worker.on("error", (error) => { + // TODO attach the error to the event somehow + const event = new Event("error"); + this.dispatchEvent(event); + }); + } + + set onmessage(f: () => void) { + throw new Error("UNIMPLEMENTED"); + } + + set onmessageerror(f: () => void) { + throw new Error("UNIMPLEMENTED"); + } + + set onerror(f: () => void) { + throw new Error("UNIMPLEMENTED"); + } + + postMessage(message: any, transfer: Array): void; + postMessage(message: any, options?: StructuredSerializeOptions | undefined): void; + postMessage(value: any, transfer: any) { + this._worker.postMessage(value, transfer); + } + + terminate() { + this._worker.terminate(); + } + }; + + + if (!$worker.isMainThread) { + const globals = globalThis as unknown as DedicatedWorkerGlobalScope; + + // This is used to create the onmessage, onmessageerror, and onerror setters + const makeSetter = (prop: string, event: string) => { + let oldvalue: () => void; + + Object.defineProperty(globals, prop, { + get() { + return oldvalue; + }, + set(value) { + if (oldvalue) { + globals.removeEventListener(event, oldvalue); + } + + oldvalue = value; + + if (oldvalue) { + globals.addEventListener(event, oldvalue); + } + }, + }); + }; + + // This makes sure that `f` is only run once + const memoize = (f: () => void) => { + let run = false; + + return () => { + if (!run) { + run = true; + f(); + } + }; + }; + + + // We only start listening for messages / errors when the worker calls addEventListener + const startOnMessage = memoize(() => { + $worker.parentPort!.on("message", (data) => { + workerEvents.dispatchEvent(new MessageEvent("message", { data })); + }); + }); + + const startOnMessageError = memoize(() => { + throw new Error("UNIMPLEMENTED"); + }); + + const startOnError = memoize(() => { + $worker.parentPort!.on("error", (data) => { + workerEvents.dispatchEvent(new Event("error")); + }); + }); + + + // Node workers don't have top-level events, so we have to make our own + const workerEvents = new EventTarget(); + + globals.close = () => { + process.exit(); + }; + + globals.addEventListener = (type: string, callback: EventListenerOrEventListenerObject | null, options?: boolean | EventListenerOptions | undefined) => { + workerEvents.addEventListener(type, callback, options); + + if (type === "message") { + startOnMessage(); + } else if (type === "messageerror") { + startOnMessageError(); + } else if (type === "error") { + startOnError(); + } + }; + + globals.removeEventListener = (type: string, callback: EventListenerOrEventListenerObject | null, options?: boolean | EventListenerOptions | undefined) => { + workerEvents.removeEventListener(type, callback, options); + }; + + function postMessage(message: any, transfer: Transferable[]): void; + function postMessage(message: any, options?: StructuredSerializeOptions | undefined): void; + function postMessage(value: any, transfer: any) { + $worker.parentPort!.postMessage(value, transfer); + } + + globals.postMessage = postMessage; + + makeSetter("onmessage", "message"); + makeSetter("onmessageerror", "messageerror"); + makeSetter("onerror", "error"); + } +} + + +async function polyfill() { + const [$worker, $os] = await Promise.all([ + import("node:worker_threads"), + import("node:os"), + ]); + + patch($worker, $os); +} + +if (globalThis.Worker == null) { + await polyfill(); +} + +export {}; \ No newline at end of file diff --git a/sdk/src/polyfill/xmlhttprequest.ts b/sdk/src/polyfill/xmlhttprequest.ts new file mode 100644 index 000000000..8036ba093 --- /dev/null +++ b/sdk/src/polyfill/xmlhttprequest.ts @@ -0,0 +1,154 @@ +import $request from "sync-request"; + + +globalThis.XMLHttpRequest = class extends EventTarget implements XMLHttpRequest { + public static readonly UNSENT = 0; + public static readonly OPENED = 1; + public static readonly HEADERS_RECEIVED = 2; + public static readonly LOADING = 3; + public static readonly DONE = 4; + + public readonly UNSENT = XMLHttpRequest.UNSENT; + public readonly OPENED = XMLHttpRequest.OPENED; + public readonly HEADERS_RECEIVED = XMLHttpRequest.HEADERS_RECEIVED; + public readonly LOADING = XMLHttpRequest.LOADING; + public readonly DONE = XMLHttpRequest.DONE; + + public responseType!: XMLHttpRequestResponseType; + public withCredentials!: boolean; + public timeout!: number; + + public readonly readyState!: number; + public readonly response!: ArrayBuffer | Blob | Document | string | null; + public readonly responseText!: string; + public readonly responseURL!: string; + public readonly responseXML!: Document | null; + public readonly status!: number; + public readonly statusText!: string; + public readonly upload!: XMLHttpRequestUpload; + + private _url!: string | URL | null; + private _mime!: string; + + constructor() { + super(); + + this._reset(); + + this._mime = "text/xml"; + } + + private _reset() { + (this as any).readyState = XMLHttpRequest.UNSENT; + (this as any).response = null; + (this as any).responseText = ""; + (this as any).responseType = ""; + (this as any).responseURL = ""; + (this as any).responseXML = null; + (this as any).status = 0; + (this as any).statusText = ""; + (this as any).timeout = 0; + (this as any).upload = null; + (this as any).withCredentials = false; + + this._url = null; + } + + private _success() { + (this as any).readyState = XMLHttpRequest.DONE; + (this as any).status = 200; + (this as any).statusText = "OK"; + } + + public set onabort(value: () => void) { + throw new Error("Not implemented"); + } + + public set onerror(value: () => void) { + throw new Error("Not implemented"); + } + + public set onreadystatechange(value: () => void) { + throw new Error("Not implemented"); + } + + public set onloadstart(value: () => void) { + throw new Error("Not implemented"); + } + + public set onload(value: () => void) { + throw new Error("Not implemented"); + } + + public set onloadend(value: () => void) { + throw new Error("Not implemented"); + } + + public set onprogress(value: () => void) { + throw new Error("Not implemented"); + } + + public set ontimeout(value: () => void) { + throw new Error("Not implemented"); + } + + public abort() { + throw new Error("Not implemented"); + } + + public overrideMimeType(mime: string) { + this._mime = mime; + } + + public getResponseHeader(): string | null { + throw new Error("Not implemented"); + } + + public getAllResponseHeaders(): string { + throw new Error("Not implemented"); + } + + public setRequestHeader() { + throw new Error("Not implemented"); + } + + public open(method: string, url: string | URL, async: boolean = true, username?: string | null | undefined, password?: string | null | undefined): void { + if (async) { + throw new Error("Async XMLHttpRequest is not implemented yet"); + } + + if (method !== "GET") { + throw new Error("Non-GET requests are not implemented yet"); + } + + this._reset(); + + this._url = url; + } + + public send(body: null = null) { + if (body !== null) { + throw new Error("XMLHttpRequest send body is not implemented yet"); + } + + if (!this._url) { + throw new Error("You must call open before you call send"); + } + + const response = $request("GET", this._url, { + headers: { + "Content-Type": this._mime, + } + }); + + const buffer = (response.body as Buffer).buffer; + + const responseText = new TextDecoder("iso-8859-5", { fatal: true }).decode(buffer); + + (this as any).response = (this as any).responseText = responseText; + + this._url = null; + + this._success(); + } +}; \ No newline at end of file diff --git a/sdk/src/program-manager.ts b/sdk/src/program-manager.ts index 9e58f1035..381794f31 100644 --- a/sdk/src/program-manager.ts +++ b/sdk/src/program-manager.ts @@ -1,7 +1,3 @@ -import init, { - initThreadPool, - ProgramManager as WasmProgramManager, -} from '@aleohq/wasm' import { Account, AleoKeyProvider, @@ -21,7 +17,8 @@ import { PRIVATE_TRANSFER_TYPES, VALID_TRANSFER_TYPES, logAndThrow, -} from "."; + ProgramManagerBase as WasmProgramManager, +} from "./index"; diff --git a/sdk/src/record-provider.ts b/sdk/src/record-provider.ts index 38e30768d..6b59c8768 100644 --- a/sdk/src/record-provider.ts +++ b/sdk/src/record-provider.ts @@ -1,4 +1,4 @@ -import { logAndThrow, RecordPlaintext } from "."; +import { logAndThrow, RecordPlaintext } from "./index"; import { Account } from "./account"; import { AleoNetworkClient } from "./network-client"; @@ -296,4 +296,4 @@ class BlockHeightSearch implements RecordSearchParams { } } -export { BlockHeightSearch, NetworkRecordProvider, RecordProvider, RecordSearchParams}; \ No newline at end of file +export { BlockHeightSearch, NetworkRecordProvider, RecordProvider, RecordSearchParams}; diff --git a/sdk/src/thread.ts b/sdk/src/thread.ts new file mode 100644 index 000000000..801ace2ee --- /dev/null +++ b/sdk/src/thread.ts @@ -0,0 +1 @@ +import "@aleohq/wasm/worker.js"; \ No newline at end of file diff --git a/sdk/src/worker.ts b/sdk/src/worker.ts index 68664b4d5..1bb6cd004 100644 --- a/sdk/src/worker.ts +++ b/sdk/src/worker.ts @@ -1,4 +1,4 @@ -import { initializeWasm, initThreadPool, ProgramManager, PrivateKey, verifyFunctionExecution } from "./browser"; +import { initializeWasm, initThreadPool, ProgramManager, PrivateKey, verifyFunctionExecution } from "./index"; import { AleoKeyProvider, AleoKeyProviderParams} from "./function-key-provider"; import { expose } from "comlink"; diff --git a/sdk/tsconfig.json b/sdk/tsconfig.json index 098dfbd98..de3592536 100644 --- a/sdk/tsconfig.json +++ b/sdk/tsconfig.json @@ -6,7 +6,7 @@ "outDir": "./dist", "target": "es2022", "module": "esnext", - "lib": ["dom", "esnext"], + "lib": ["dom", "esnext", "webworker"], "importHelpers": true, // output .d.ts declaration files for consumers "declaration": true, diff --git a/wasm/Cargo.lock b/wasm/Cargo.lock index bc9832649..192f0e431 100644 --- a/wasm/Cargo.lock +++ b/wasm/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "addr2line" -version = "0.20.0" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4fa78e18c64fce05e902adecd7a5eed15a5e0a3439f7b0e169f0252214865e3" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" dependencies = [ "gimli", ] @@ -70,7 +70,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72f2a841f04c2eaeb5a95312e5201a9e4b7c95b64ca99870d6bd2e2376df540a" dependencies = [ "proc-macro2", - "quote 1.0.32", + "quote 1.0.33", "syn 1.0.109", ] @@ -81,7 +81,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6118baab6285accf088b31d5ea5029c37bbf9d98e62b4d8720a0a5a66bc2e427" dependencies = [ "proc-macro2", - "quote 1.0.32", + "quote 1.0.33", "syn 1.0.109", ] @@ -93,13 +93,14 @@ checksum = "7e4f181fc1a372e8ceff89612e5c9b13f72bff5b066da9f8d6827ae65af492c4" [[package]] name = "aleo-wasm" -version = "0.5.10" +version = "0.6.0" dependencies = [ "anyhow", "console_error_panic_hook", + "futures", "getrandom", "hex", - "indexmap 2.0.0", + "indexmap 2.0.2", "js-sys", "lazy_static", "once_cell", @@ -116,11 +117,12 @@ dependencies = [ "snarkvm-parameters", "snarkvm-synthesizer", "snarkvm-wasm", + "spmc", "walkdir", "wasm-bindgen", "wasm-bindgen-futures", - "wasm-bindgen-rayon", "wasm-bindgen-test", + "web-sys", ] [[package]] @@ -154,8 +156,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bc00ceb34980c03614e35a3a4e218276a0a824e911d07651cd0d858a51e8c0f0" dependencies = [ "proc-macro2", - "quote 1.0.32", - "syn 2.0.28", + "quote 1.0.33", + "syn 2.0.37", ] [[package]] @@ -166,9 +168,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "backtrace" -version = "0.3.68" +version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4319208da049c43661739c5fade2ba182f09d1dc2299b32298d3a31692b17e12" +checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" dependencies = [ "addr2line", "cc", @@ -181,9 +183,9 @@ dependencies = [ [[package]] name = "base64" -version = "0.21.2" +version = "0.21.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "604178f6c5c21f02dc555784810edfb88d34ac2c73b2eae109655649ee73ce3d" +checksum = "9ba43ea6f343b788c8764558649e08df62f86c6ef251fdaeb1ffd010a9ae50a2" [[package]] name = "bech32" @@ -223,9 +225,9 @@ dependencies = [ [[package]] name = "blake2s_simd" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6637f448b9e61dfadbdcbae9a885fadee1f3eaffb1f8d3c1965d3ade8bdfd44f" +checksum = "94230421e395b9920d23df13ea5d77a20e1725331f90fbbf6df6040b33f756ae" dependencies = [ "arrayref", "arrayvec", @@ -252,9 +254,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.13.0" +version = "3.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" +checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" [[package]] name = "byteorder" @@ -264,15 +266,15 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "bytes" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" +checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" [[package]] name = "cc" -version = "1.0.82" +version = "1.0.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "305fe645edc1442a0fa8b6726ba61d422798d37a52e12eaecf4b022ebbb88f01" +checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" dependencies = [ "libc", ] @@ -306,9 +308,9 @@ dependencies = [ [[package]] name = "constant_time_eq" -version = "0.2.6" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21a53c0a4d288377e7415b53dcfc3c04da5cdc2cc95c8d5ac178b58f0b861ad6" +checksum = "f7144d30dcf0fafbce74250a3963025d8d52177934239851c917d29f1df280c2" [[package]] name = "core-foundation" @@ -344,16 +346,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "crossbeam-channel" -version = "0.5.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" -dependencies = [ - "cfg-if", - "crossbeam-utils", -] - [[package]] name = "crossbeam-deque" version = "0.8.3" @@ -420,9 +412,9 @@ dependencies = [ [[package]] name = "curl-sys" -version = "0.4.65+curl-8.2.1" +version = "0.4.66+curl-8.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "961ba061c9ef2fe34bbd12b807152d96f0badd2bebe7b90ce6c8c8b7572a0986" +checksum = "70c44a72e830f0e40ad90dda8a6ab6ed6314d39776599a58a2e5e37fbc6db5b9" dependencies = [ "cc", "libc", @@ -430,7 +422,7 @@ dependencies = [ "openssl-sys", "pkg-config", "vcpkg", - "winapi", + "windows-sys", ] [[package]] @@ -440,7 +432,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" dependencies = [ "proc-macro2", - "quote 1.0.32", + "quote 1.0.33", "syn 1.0.109", ] @@ -547,9 +539,9 @@ checksum = "a246d82be1c9d791c5dfde9a2bd045fc3cbba3fa2b11ad558f27d01712f00569" [[package]] name = "encoding_rs" -version = "0.8.32" +version = "0.8.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "071a31f4ee85403370b58aca746f01041ede6f0da2730960ad001edc2b71b394" +checksum = "7268b386296a025e474d5140678f75d6de9493ae55a5d709eeb9dd08149945e1" dependencies = [ "cfg-if", ] @@ -578,9 +570,9 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" -version = "0.3.2" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b30f669a7961ef1631673d2766cc92f52d64f7ef354d4fe0ddfd30ed52f0f4f" +checksum = "add4f07d43996f76ef320709726a556a9d4f965d9410d8d0271132d2f8293480" dependencies = [ "errno-dragonfly", "libc", @@ -599,9 +591,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "2.0.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6999dc1837253364c2ebb0704ba97994bd874e8f195d665c50b7548f6ea92764" +checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" [[package]] name = "flate2" @@ -643,6 +635,21 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "futures" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + [[package]] name = "futures-channel" version = "0.3.28" @@ -650,6 +657,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" dependencies = [ "futures-core", + "futures-sink", ] [[package]] @@ -658,6 +666,34 @@ version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" +[[package]] +name = "futures-executor" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" + +[[package]] +name = "futures-macro" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" +dependencies = [ + "proc-macro2", + "quote 1.0.33", + "syn 2.0.37", +] + [[package]] name = "futures-sink" version = "0.3.28" @@ -676,10 +712,16 @@ version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" dependencies = [ + "futures-channel", "futures-core", + "futures-io", + "futures-macro", + "futures-sink", "futures-task", + "memchr", "pin-project-lite", "pin-utils", + "slab", ] [[package]] @@ -716,15 +758,15 @@ dependencies = [ [[package]] name = "gimli" -version = "0.27.3" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e" +checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" [[package]] name = "h2" -version = "0.3.20" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97ec8491ebaf99c8eaa73058b045fe58073cd6be7f596ac993ced0b0a0c01049" +checksum = "91fc23aa11be92976ef4729127f1a74adf36d8436f7816b185d18df956790833" dependencies = [ "bytes", "fnv", @@ -747,9 +789,9 @@ checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "hashbrown" -version = "0.14.0" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" +checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12" dependencies = [ "ahash", "allocator-api2", @@ -757,9 +799,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" +checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" [[package]] name = "hex" @@ -860,12 +902,12 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.0.0" +version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d" +checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" dependencies = [ "equivalent", - "hashbrown 0.14.0", + "hashbrown 0.14.1", "rayon", "serde", ] @@ -919,9 +961,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.147" +version = "0.2.148" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" +checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b" [[package]] name = "libz-sys" @@ -937,9 +979,9 @@ dependencies = [ [[package]] name = "linux-raw-sys" -version = "0.4.5" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57bcfdad1b858c2db7c38303a6d2ad4dfaf5eb53dfeb0910128b2c26d6158503" +checksum = "3852614a3bd9ca9804678ba6be5e3b8ce76dfc902cae004e3e0c44051b6e88db" [[package]] name = "lock_api" @@ -959,9 +1001,9 @@ checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" [[package]] name = "memchr" -version = "2.5.0" +version = "2.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" [[package]] name = "memoffset" @@ -1034,9 +1076,9 @@ dependencies = [ [[package]] name = "num-bigint" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f" +checksum = "608e7659b5c3d7cba262d894801b9ec9d00de989e8a82bd4bef91d08da45cdc0" dependencies = [ "autocfg", "num-integer", @@ -1050,8 +1092,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e6a0fd4f737c707bd9086cc16c925f294943eb62eb71499e9fd4cf71f8b9f4e" dependencies = [ "proc-macro2", - "quote 1.0.32", - "syn 2.0.28", + "quote 1.0.33", + "syn 2.0.37", ] [[package]] @@ -1085,9 +1127,9 @@ dependencies = [ [[package]] name = "object" -version = "0.31.1" +version = "0.32.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bda667d9f2b5051b8833f59f3bf748b28ef54f850f4fcb389a252aa383866d1" +checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0" dependencies = [ "memchr", ] @@ -1100,11 +1142,11 @@ checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" [[package]] name = "openssl" -version = "0.10.56" +version = "0.10.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "729b745ad4a5575dd06a3e1af1414bd330ee561c01b3899eb584baeaa8def17e" +checksum = "bac25ee399abb46215765b1cb35bc0212377e58a061560d8b29b024fd0430e7c" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.4.0", "cfg-if", "foreign-types", "libc", @@ -1120,8 +1162,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", - "quote 1.0.32", - "syn 2.0.28", + "quote 1.0.33", + "syn 2.0.37", ] [[package]] @@ -1132,9 +1174,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.91" +version = "0.9.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "866b5f16f90776b9bb8dc1e1802ac6f0513de3a7a7465867bfbc563dc737faac" +checksum = "db4d56a4c0478783083cfafcc42493dd4a981d41669da64b4572a2a089b51b1d" dependencies = [ "cc", "libc", @@ -1179,9 +1221,9 @@ checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" [[package]] name = "pin-project-lite" -version = "0.2.12" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12cc1b0bf1727a77a54b6654e7b5f1af8604923edc8b81885f8ec92f9e3f0a05" +checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" [[package]] name = "pin-utils" @@ -1203,9 +1245,9 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro2" -version = "1.0.66" +version = "1.0.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" +checksum = "3d433d9f1a3e8c1263d9456598b16fec66f4acc9a74dacffd35c7bb09b3a1328" dependencies = [ "unicode-ident", ] @@ -1218,9 +1260,9 @@ checksum = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" [[package]] name = "quote" -version = "1.0.32" +version = "1.0.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50f3b39ccfb720540debaa0164757101c08ecb8d326b15358ce76a62c7e85965" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" dependencies = [ "proc-macro2", ] @@ -1266,9 +1308,9 @@ dependencies = [ [[package]] name = "rayon" -version = "1.7.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d2df5196e37bcc87abebc0053e20787d73847bb33134a69841207dd0a47f03b" +checksum = "9c27db03db7734835b3f53954b534c91069375ce6ccaa2e065441e07d9b6cdb1" dependencies = [ "either", "rayon-core", @@ -1276,14 +1318,12 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.11.0" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b8f95bd6966f5c87776639160a66bd8ab9895d9d4ab01ddba9fc60661aebe8d" +checksum = "5ce3fb6ad83f861aac485e76e1985cd109d9a3713802152be56c3b1f0e0658ed" dependencies = [ - "crossbeam-channel", "crossbeam-deque", "crossbeam-utils", - "num_cpus", ] [[package]] @@ -1317,9 +1357,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.11.20" +version = "0.11.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e9ad3fe7488d7e34558a2033d45a0c90b72d97b4f80705666fea71472e2e6a1" +checksum = "046cd98826c46c2ac8ddecae268eb5c2e58628688a5fc7a2643704a73faba95b" dependencies = [ "base64", "bytes", @@ -1342,6 +1382,7 @@ dependencies = [ "serde", "serde_json", "serde_urlencoded", + "system-configuration", "tokio", "tokio-native-tls", "tower-service", @@ -1384,9 +1425,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.8" +version = "0.38.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19ed4fa021d81c8392ce04db050a3da9a60299050b7ae1cf482d862b54a7218f" +checksum = "d2f9da0cbd88f9f09e7814e388301c8414c51c62aa6ce1e4b5c551d49d96e531" dependencies = [ "bitflags 2.4.0", "errno", @@ -1397,31 +1438,21 @@ dependencies = [ [[package]] name = "rustls" -version = "0.21.6" +version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d1feddffcfcc0b33f5c6ce9a29e341e4cd59c3f78e7ee45f4a40c038b1d6cbb" +checksum = "cd8d6c9f025a446bc4d18ad9632e69aec8f287aa84499ee335599fabd20c3fd8" dependencies = [ "log", "ring", - "rustls-webpki 0.101.3", + "rustls-webpki", "sct", ] [[package]] name = "rustls-webpki" -version = "0.100.2" +version = "0.101.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e98ff011474fa39949b7e5c0428f9b4937eda7da7848bbb947786b7be0b27dab" -dependencies = [ - "ring", - "untrusted", -] - -[[package]] -name = "rustls-webpki" -version = "0.101.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "261e9e0888cba427c3316e6322805653c9425240b6fd96cee7cb671ab70ab8d0" +checksum = "3c7d5dece342910d9ba34d259310cae3e0154b873b35408b787b59bce53d34fe" dependencies = [ "ring", "untrusted", @@ -1498,9 +1529,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.18" +version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918" +checksum = "ad977052201c6de01a8ef2aa3378c4bd23217a056337d1d6da40468d267a4fb0" [[package]] name = "serde" @@ -1518,17 +1549,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" dependencies = [ "proc-macro2", - "quote 1.0.32", - "syn 2.0.28", + "quote 1.0.33", + "syn 2.0.37", ] [[package]] name = "serde_json" -version = "1.0.105" +version = "1.0.107" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "693151e1ac27563d6dbcec9dee9fbd5da8539b20fa14ad3752b2e6d363ace360" +checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" dependencies = [ - "indexmap 2.0.0", + "indexmap 2.0.2", "itoa", "ryu", "serde", @@ -1548,9 +1579,9 @@ dependencies = [ [[package]] name = "sha2" -version = "0.10.7" +version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "479fb9d862239e610720565ca91403019f2f00410f1864c5aa7479b950a76ed8" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" dependencies = [ "cfg-if", "cpufeatures", @@ -1559,18 +1590,18 @@ dependencies = [ [[package]] name = "slab" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" dependencies = [ "autocfg", ] [[package]] name = "smallvec" -version = "1.11.0" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" +checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" [[package]] name = "smol_str" @@ -1592,9 +1623,9 @@ dependencies = [ "blake2", "cfg-if", "fxhash", - "hashbrown 0.14.0", + "hashbrown 0.14.1", "hex", - "indexmap 2.0.0", + "indexmap 2.0.2", "itertools", "num-traits", "parking_lot", @@ -1668,7 +1699,7 @@ version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8011e5f75c8234d44f03aebbda34417df73ea828d4666ea349c92de52ec34aef" dependencies = [ - "indexmap 2.0.0", + "indexmap 2.0.2", "itertools", "nom", "num-traits", @@ -1875,7 +1906,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7e45e9fcb3fb7e1167d979353897bfda3b12070a430a97c7135e2a6d79170d8e" dependencies = [ "anyhow", - "indexmap 2.0.0", + "indexmap 2.0.2", "itertools", "lazy_static", "once_cell", @@ -1918,7 +1949,7 @@ checksum = "453c56a9a45b58969e6a81ce7fe671aa872ba2460d60c585a613f4e1a8e88d7d" dependencies = [ "enum_index", "enum_index_derive", - "indexmap 2.0.0", + "indexmap 2.0.2", "num-derive", "num-traits", "once_cell", @@ -2078,7 +2109,7 @@ version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d21d3b25e5b49c5ea441f0203bb3ce491a0c423631148fe15fab1c2fce97f0d7" dependencies = [ - "indexmap 2.0.0", + "indexmap 2.0.2", "rayon", "serde_json", "snarkvm-console", @@ -2101,7 +2132,7 @@ dependencies = [ "anyhow", "bincode", "blake2", - "indexmap 2.0.0", + "indexmap 2.0.2", "rayon", "serde_json", "snarkvm-algorithms", @@ -2118,7 +2149,7 @@ version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d96fc53698ea966e552a5b7f1a2474237083d4580d9e4ab3b65b6b4a3129d9e9" dependencies = [ - "indexmap 2.0.0", + "indexmap 2.0.2", "serde_json", "snarkvm-console", ] @@ -2129,7 +2160,7 @@ version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "11de15ddce02084d13abc86a2f041793ea58d3f3d136b2f973fe0dcf3feaeaab" dependencies = [ - "indexmap 2.0.0", + "indexmap 2.0.2", "serde_json", "snarkvm-console", "snarkvm-ledger-narwhal-batch-header", @@ -2142,7 +2173,7 @@ version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b0bf0a06ba661645094f3fc9bbeea60c49debdd5760846cfc12039cea25e9d3" dependencies = [ - "indexmap 2.0.0", + "indexmap 2.0.2", "serde_json", "snarkvm-console", "snarkvm-ledger-narwhal-transmission-id", @@ -2154,7 +2185,7 @@ version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "03d432264a95069aaaf5a56c20e9c4a8c84a5e05879cd6acffb49bc2592f1f7e" dependencies = [ - "indexmap 2.0.0", + "indexmap 2.0.2", "serde_json", "snarkvm-console", "snarkvm-ledger-narwhal-batch-certificate", @@ -2193,7 +2224,7 @@ checksum = "01dd397b65143928e6fda58bd6edb293bb63dadc1792e55ac9e133e24c568db3" dependencies = [ "anyhow", "bincode", - "indexmap 2.0.0", + "indexmap 2.0.2", "parking_lot", "rayon", "serde", @@ -2221,7 +2252,7 @@ dependencies = [ "curl", "encoding", "hex", - "indexmap 2.0.0", + "indexmap 2.0.2", "itertools", "js-sys", "lazy_static", @@ -2243,7 +2274,7 @@ checksum = "fbd290bfaffc486fd50ff1e1599d77562ec7ca5f9096f27cbf8e363a8b412312" dependencies = [ "aleo-std", "anyhow", - "indexmap 2.0.0", + "indexmap 2.0.2", "parking_lot", "rand", "rayon", @@ -2268,7 +2299,7 @@ checksum = "6a7112af2bd2c672e9a0fcc4dd793cd4237597125a7622840b478e5d95d9152b" dependencies = [ "aleo-std", "colored", - "indexmap 2.0.0", + "indexmap 2.0.2", "once_cell", "parking_lot", "rand", @@ -2288,7 +2319,7 @@ version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4e6114d30750a072037a11c1ad4fb16db24fe478802da7fc42ef3a3cc2258268" dependencies = [ - "indexmap 2.0.0", + "indexmap 2.0.2", "paste", "rand", "rand_chacha", @@ -2339,8 +2370,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b5b1d2f74b47cc28a4199a11c67ef1056c49a77105b83d8e1fbd18a3279d20a" dependencies = [ "proc-macro2", - "quote 1.0.32", - "syn 2.0.28", + "quote 1.0.33", + "syn 2.0.37", ] [[package]] @@ -2372,9 +2403,9 @@ dependencies = [ [[package]] name = "socket2" -version = "0.5.3" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2538b18701741680e0322a2302176d3253a35388e2e62f172f64f4f16605f877" +checksum = "4031e820eb552adee9295814c0ced9e5cf38ddf1e8b7d566d6de8e2538ea989e" dependencies = [ "libc", "windows-sys", @@ -2416,18 +2447,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ "proc-macro2", - "quote 1.0.32", + "quote 1.0.33", "unicode-ident", ] [[package]] name = "syn" -version = "2.0.28" +version = "2.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04361975b3f5e348b2189d8dc55bc942f278b2d482a6a0365de5bdd62d351567" +checksum = "7303ef2c05cd654186cb250d29049a24840ca25d2747c25c0381c8d9e2f582e8" dependencies = [ "proc-macro2", - "quote 1.0.32", + "quote 1.0.33", "unicode-ident", ] @@ -2440,11 +2471,32 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "system-configuration" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "tempfile" -version = "3.7.1" +version = "3.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc02fddf48964c42031a0b3fe0428320ecf3a73c401040fc0096f97794310651" +checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef" dependencies = [ "cfg-if", "fastrand", @@ -2455,22 +2507,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.46" +version = "1.0.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9207952ae1a003f42d3d5e892dac3c6ba42aa6ac0c79a6a91a2b5cb4253e75c" +checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.46" +version = "1.0.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1728216d3244de4f14f14f8c15c79be1a7c67867d28d69b719690e2a19fb445" +checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" dependencies = [ "proc-macro2", - "quote 1.0.32", - "syn 2.0.28", + "quote 1.0.33", + "syn 2.0.37", ] [[package]] @@ -2508,7 +2560,7 @@ dependencies = [ "libc", "mio", "pin-project-lite", - "socket2 0.5.3", + "socket2 0.5.4", "windows-sys", ] @@ -2524,9 +2576,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.8" +version = "0.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "806fe8c2c87eccc8b3267cbae29ed3ab2d0bd37fca70ab622e46aaa9375ddb7d" +checksum = "1d68074620f57a0b21594d9735eb2e98ab38b17f80d3fcb189fca266771ca60d" dependencies = [ "bytes", "futures-core", @@ -2561,8 +2613,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" dependencies = [ "proc-macro2", - "quote 1.0.32", - "syn 2.0.28", + "quote 1.0.33", + "syn 2.0.37", ] [[package]] @@ -2582,9 +2634,9 @@ checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" [[package]] name = "typenum" -version = "1.16.0" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "unicode-bidi" @@ -2594,9 +2646,9 @@ checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" [[package]] name = "unicode-ident" -version = "1.0.11" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unicode-normalization" @@ -2621,16 +2673,16 @@ checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" [[package]] name = "ureq" -version = "2.7.1" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b11c96ac7ee530603dcdf68ed1557050f374ce55a5a07193ebf8cbc9f8927e9" +checksum = "f5ccd538d4a604753ebc2f17cd9946e89b77bf87f6a8e2309667c6f2e87855e3" dependencies = [ "base64", "flate2", "log", "once_cell", "rustls", - "rustls-webpki 0.100.2", + "rustls-webpki", "serde", "serde_json", "url", @@ -2639,9 +2691,9 @@ dependencies = [ [[package]] name = "url" -version = "2.4.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50bff7831e19200a85b17131d085c25d7811bc4e186efdaf54bbd132994a88cb" +checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5" dependencies = [ "form_urlencoded", "idna", @@ -2662,9 +2714,9 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "walkdir" -version = "2.3.3" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36df944cda56c7d8d8b7496af378e6b16de9284591917d307c9b4d313c44e698" +checksum = "d71d857dc86794ca4c280d616f7da00d2dbfd8cd788846559a6813e6aa4b54ee" dependencies = [ "same-file", "winapi-util", @@ -2707,8 +2759,8 @@ dependencies = [ "log", "once_cell", "proc-macro2", - "quote 1.0.32", - "syn 2.0.28", + "quote 1.0.33", + "syn 2.0.37", "wasm-bindgen-shared", ] @@ -2730,7 +2782,7 @@ version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d" dependencies = [ - "quote 1.0.32", + "quote 1.0.33", "wasm-bindgen-macro-support", ] @@ -2741,24 +2793,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", - "quote 1.0.32", - "syn 2.0.28", + "quote 1.0.33", + "syn 2.0.37", "wasm-bindgen-backend", "wasm-bindgen-shared", ] -[[package]] -name = "wasm-bindgen-rayon" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df87c67450805c305d3ae44a3ac537b0253d029153c25afc3ecd2edc36ccafb1" -dependencies = [ - "js-sys", - "rayon", - "spmc", - "wasm-bindgen", -] - [[package]] name = "wasm-bindgen-shared" version = "0.2.87" @@ -2786,7 +2826,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ecb993dd8c836930ed130e020e77d9b2e65dd0fbab1b67c790b0f5d80b11a575" dependencies = [ "proc-macro2", - "quote 1.0.32", + "quote 1.0.33", ] [[package]] @@ -2801,12 +2841,9 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "0.23.1" +version = "0.25.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b03058f88386e5ff5310d9111d53f48b17d732b401aeb83a8d5190f2ac459338" -dependencies = [ - "rustls-webpki 0.100.2", -] +checksum = "14247bb57be4f377dfb94c72830b8ce8fc6beac03cf4bf7b9732eadd414123fc" [[package]] name = "winapi" @@ -2826,9 +2863,9 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" dependencies = [ "winapi", ] @@ -2850,9 +2887,9 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.48.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1eeca1c172a285ee6c2c84c341ccea837e7c01b12fbb2d0fe3c9e550ce49ec8" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", @@ -2865,45 +2902,45 @@ dependencies = [ [[package]] name = "windows_aarch64_gnullvm" -version = "0.48.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b10d0c968ba7f6166195e13d593af609ec2e3d24f916f081690695cf5eaffb2f" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_msvc" -version = "0.48.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "571d8d4e62f26d4932099a9efe89660e8bd5087775a2ab5cdd8b747b811f1058" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_i686_gnu" -version = "0.48.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2229ad223e178db5fbbc8bd8d3835e51e566b8474bfca58d2e6150c48bb723cd" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_msvc" -version = "0.48.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "600956e2d840c194eedfc5d18f8242bc2e17c7775b6684488af3a9fff6fe3287" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_x86_64_gnu" -version = "0.48.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea99ff3f8b49fb7a8e0d305e5aec485bd068c2ba691b6e277d29eaeac945868a" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnullvm" -version = "0.48.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f1a05a1ece9a7a0d5a7ccf30ba2c33e3a61a30e042ffd247567d1de1d94120d" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_msvc" -version = "0.48.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d419259aba16b663966e29e6d7c6ecfa0bb8425818bb96f6f1f3c3eb71a6e7b9" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "winreg" diff --git a/wasm/Cargo.toml b/wasm/Cargo.toml index 776f507c0..a60a25588 100644 --- a/wasm/Cargo.toml +++ b/wasm/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "aleo-wasm" -version = "0.5.10" +version = "0.6.0" authors = [ "The Aleo Team " ] description = "WebAssembly based toolkit for developing zero knowledge applications with Aleo" homepage = "https://aleo.org" @@ -72,8 +72,7 @@ version = "1.18.0" version = "0.8" [dependencies.rayon] -version = "1.5" -optional = true +version = "1.8" [dependencies.reqwest] version = "0.11.18" @@ -91,10 +90,6 @@ features = [ "serde-serialize" ] [dependencies.wasm-bindgen-futures] version = "0.4.37" -[dependencies.wasm-bindgen-rayon] -version = "1.0.3" -optional = true - [dependencies.console_error_panic_hook] version = "0.1.7" @@ -105,13 +100,25 @@ version = "1.0.183" version = "0.15.0" features = [ "wasm" ] +[dependencies.spmc] +version = "0.3.0" + +[dependencies.futures] +version = "0.3.28" + +[dependencies.web-sys] +version = "0.3.64" +features = [ + "Url", + "Navigator", +] + [dev-dependencies.wasm-bindgen-test] version = "0.3.37" [features] default = [ "serial", "browser" ] serial = [ "snarkvm-console/serial", "snarkvm-synthesizer/serial", "snarkvm-ledger-query/serial", "snarkvm-ledger-block/serial", "snarkvm-ledger-store/serial" ] -parallel = [ "wasm-bindgen-rayon", "rayon" ] browser = [ ] ## Profiles @@ -123,9 +130,3 @@ lto = true opt-level = 3 lto = "thin" incremental = true - -[package.metadata.wasm-pack.profile.debug] -wasm-opt = ["-O3"] - -[package.metadata.wasm-pack.profile.release] -wasm-opt = ["-O3"] \ No newline at end of file diff --git a/wasm/PUBLISH.md b/wasm/PUBLISH.md index 9f8cdd594..54ca03d87 100644 --- a/wasm/PUBLISH.md +++ b/wasm/PUBLISH.md @@ -4,8 +4,6 @@ ```bash npm login -export RUSTFLAGS='-C target-feature=+atomics,+bulk-memory,+mutable-globals -C link-arg=--max-memory=4294967296' && rustup run nightly-2023-05-24 wasm-pack build --release --target web --scope aleohq --out-dir pkg-parallel -- --features "parallel, browser" --no-default-features -Z build-std=panic_abort,std -node prepublish -cd pkg-parallel +npm run build npm publish --access=public ``` \ No newline at end of file diff --git a/wasm/README.md b/wasm/README.md index 6443dc787..cf9ede417 100644 --- a/wasm/README.md +++ b/wasm/README.md @@ -27,94 +27,21 @@ Functionality exposed by this crate includes: More information on these concepts can be found at the [Aleo Developer Hub](https://developer.aleo.org/concepts). ## Usage -The [wasm-pack](https://crates.io/crates/wasm-pack) tool is used to compile the Rust code in this crate into JavaScript -modules which can be imported into other JavaScript projects. - -#### Install Wasm-Pack -```bash -curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh -``` - -### Build Instructions -The general syntax for compiling rust into WebAssembly based JavaScript modules with -[wasm-pack](https://crates.io/crates/wasm-pack) is as follows: -```bash -wasm-pack build --target --out-dir -- --features -``` - -Invoking this command will build a JavaScript module in the current directory with the default name `pkg` (which can -be changed as necessary using the `--out-dir` flag). This folder can then be imported directly as a JavaScript module -by other JavaScript modules. - -There are 3 possible JavaScript modules that [wasm-pack](https://crates.io/crates/wasm-pack) can be used to generate -when run within this crate: -1. **NodeJS module:** Used to build NodeJS applications. -2. **Single-Threaded browser module:** Used to build browser-based web applications. -3. **Multi-Threaded browser module:** Used to build browser-based web applications which use web-worker based -multi-threading to achieve significant performance increases. - -These 3 modules and how to build them are explained in more detail below. - -### 1. NodeJS Module -This module has the features of the NodeJS environment built-in. It is single-threaded and unfortunately cannot yet be -used to generate Aleo program executions or deployments due to current Aleo protocol limitations. It can however still -be used to perform Aleo account, record, and program management tasks. - -#### Build Instructions -```bash -wasm-pack build --release --target nodejs -- --features "serial" --no-default-features -``` +The [rollup-plugin-rust](https://github.com/wasm-tool/rollup-plugin-rust/) tool is used to compile the Rust code in this crate into JavaScript +modules which can be imported into other JavaScript projects. -### 2. Single-Threaded browser module +#### Installation -This module is very similar to the NodeJS module, however it is built to make use browser-based JavaScript environments -and can be used for program execution and deployment. +Follow the [installation instructions](https://github.com/wasm-tool/rollup-plugin-rust/#installation) on the rollup-plugin-rust README. -If used for program execution or deployment, it suggested to do so on a web-worker as these operations are long-running -and will cause a browser window to hang if run in the main thread. +### Build Instructions -#### Build Instructions ```bash -wasm-pack build --release --target web +npm run build ``` -If you are intending to use this for program execution or deployment, it is recommended to build -with maximum or close to maximum memory allocation (which is 4 gigabytes for wasm). - -```bash -RUSTFLAGS='-C link-arg=--max-memory=4294967296' wasm-pack build --release --target web -```` - -### 3. Multi-Threaded browser module - -This module is also built for browser-based JavaScript environments, however it is built to make use of Rust-native -threading via web-workers (using the approach outlined in the `rayon-wasm-bindgen` crate). It is the most complex to use, -but it will run significantly faster when performing Aleo program executions and deployments and should be the choice for -performance-critical applications. - -To build with threading enabled, it is necessary to use `nightly Rust` and set certain `RUSTFLAGS` to enable the -necessary threading features. The `wasm-pack` build command is shown below. -```bash -# Set rustflags to enable atomics, -# bulk-memory, and mutable-globals. -# Also, set the maximum memory to -# 4294967296 bytes (4GB). -export RUSTFLAGS='-C target-feature=+atomics,+bulk-memory,+mutable-globals -C link-arg=--max-memory=4294967296' - -# Use rustup to run the following commands -# with the nightly version of Rust. -rustup run nightly \ - -# Use wasm-pack to build the project. -# Specify the 'parallel' feature for -# multi-threading and the 'browser' -# feature to enable program execution -# and include necessary unstable options -# using -Z -wasm-pack build --release --target web --out-dir pkg-parallel \ --- --features "parallel, browser" --no-default-features -Z build-std=panic_abort,std -``` +This will produce `.js` and `.wasm` files inside of the `dist` folder. ## Testing diff --git a/wasm/build.rs b/wasm/build.rs index 2ce105d5a..932f3bfe5 100644 --- a/wasm/build.rs +++ b/wasm/build.rs @@ -22,7 +22,7 @@ use walkdir::WalkDir; const EXPECTED_LICENSE_TEXT: &[u8] = include_bytes!("../.resources/license_header"); // The following directories will be excluded from the license scan. -const DIRS_TO_SKIP: [&str; 8] = [".cargo", ".circleci", ".git", ".github", ".resources", "examples", "sdk", "target"]; +const DIRS_TO_SKIP: [&str; 9] = [".cargo", ".circleci", ".git", ".github", ".resources", "examples", "sdk", "target", "node_modules"]; fn check_file_licenses>(path: P) { let path = path.as_ref(); diff --git a/wasm/js/index.js b/wasm/js/index.js new file mode 100644 index 000000000..0efc5d1ba --- /dev/null +++ b/wasm/js/index.js @@ -0,0 +1,43 @@ +import wasm from "../Cargo.toml"; + +const { + initThreadPool, + Address, + ExecutionResponse, + Private, + PrivateKey, + PrivateKeyCiphertext, + Program, + ProvingKey, + RecordCiphertext, + RecordPlaintext, + ProgramManager, + Signature, + Transaction, + ViewKey, + VerifyingKey, + verifyFunctionExecution, +} = await wasm({ + importHook: (path) => { + return new URL(path, import.meta.url); + }, +}); + +export { + initThreadPool, + Address, + ExecutionResponse, + Private, + PrivateKey, + PrivateKeyCiphertext, + Program, + ProvingKey, + RecordCiphertext, + RecordPlaintext, + ProgramManager, + Signature, + Transaction, + ViewKey, + VerifyingKey, + verifyFunctionExecution, +}; \ No newline at end of file diff --git a/wasm/js/types/index.d.ts b/wasm/js/types/index.d.ts new file mode 100644 index 000000000..8888ef115 --- /dev/null +++ b/wasm/js/types/index.d.ts @@ -0,0 +1,18 @@ +export { + initThreadPool, + Address, + ExecutionResponse, + Private, + PrivateKey, + PrivateKeyCiphertext, + Program, + ProvingKey, + RecordCiphertext, + RecordPlaintext, + ProgramManager, + Signature, + Transaction, + ViewKey, + VerifyingKey, + verifyFunctionExecution, +} from "./crates/aleo_wasm"; \ No newline at end of file diff --git a/wasm/js/types/worker.d.ts b/wasm/js/types/worker.d.ts new file mode 100644 index 000000000..8cec2e9ce --- /dev/null +++ b/wasm/js/types/worker.d.ts @@ -0,0 +1 @@ +export {}; \ No newline at end of file diff --git a/wasm/js/worker.js b/wasm/js/worker.js new file mode 100644 index 000000000..107e7f739 --- /dev/null +++ b/wasm/js/worker.js @@ -0,0 +1,31 @@ +import wasm from "../Cargo.toml"; + +async function initializeWorker(wasm) { + function wait() { + return new Promise((resolve) => { + addEventListener("message", (event) => { + resolve(event.data); + }, { + capture: true, + once: true, + }); + }); + } + + const [initWasm, { module, memory, address }] = await Promise.all([ + wasm, + wait(), + ]); + + const exports = await initWasm({ + initializeHook: (init, path) => init(module, memory), + }); + + postMessage(null); + + exports.initializeWorker(address); + + close(); +} + +await initializeWorker(wasm); diff --git a/wasm/package.json b/wasm/package.json new file mode 100644 index 000000000..1a07bc511 --- /dev/null +++ b/wasm/package.json @@ -0,0 +1,46 @@ +{ + "name": "@aleohq/wasm", + "version": "0.6.0", + "description": "Wasm build for the SDK", + "collaborators": [ + "The Aleo Team " + ], + "license": "GPL-3.0", + "type": "module", + "main": "./dist/index.js", + "browser": "./dist/index.js", + "types": "./dist/index.d.ts", + "exports": { + ".": "./dist/index.js", + "./worker.js": "./dist/worker.js" + }, + "files": [ + "dist", + "LICENSE.md", + "README.md" + ], + "scripts": { + "build": "rimraf dist && rollup -c rollup.config.js && cpr js/types dist", + "prepublish": "npm run build" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/AleoHQ/sdk.git" + }, + "keywords": [ + "Aleo", + "Blockchain", + "Zero Knowledge", + "ZK" + ], + "bugs": { + "url": "https://github.com/AleoHQ/sdk/issues" + }, + "homepage": "https://github.com/AleoHQ/sdk#readme", + "devDependencies": { + "@wasm-tool/rollup-plugin-rust": "^2.4.2", + "cpr": "^3.0.1", + "rimraf": "^5.0.1", + "rollup": "^3.27.2" + } +} diff --git a/wasm/prepublish.js b/wasm/prepublish.js deleted file mode 100644 index a5dd18b6d..000000000 --- a/wasm/prepublish.js +++ /dev/null @@ -1,27 +0,0 @@ -const fs = require('fs'); -const path = require('path'); - -try { - const pkgPath = path.join(__dirname, "pkg-parallel/package.json"); - - // Check if package.json exists - if (!fs.existsSync(pkgPath)) { - console.error(`Error: File ${pkgPath} not found.`); - process.exit(1); - } - - const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8')); - - // Add snippets to the files array. If no files array exists, create one. - pkg.files = pkg.files || []; - if (!pkg.files.includes('snippets/')) { - pkg.files.push('snippets/'); - fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2)); - console.log('Successfully added "snippets/" to package.json.'); - } else { - console.log('"snippets/" already exists in package.json.'); - } -} catch (error) { - console.error(`An error occurred: ${error.message}`); - process.exit(1); -} \ No newline at end of file diff --git a/wasm/rollup.config.js b/wasm/rollup.config.js new file mode 100644 index 000000000..45e0e331d --- /dev/null +++ b/wasm/rollup.config.js @@ -0,0 +1,28 @@ +import rust from "@wasm-tool/rollup-plugin-rust"; + +export default { + input: { + index: "./js/index.js", + worker: "./js/worker.js", + }, + output: { + dir: `dist`, + format: "es", + sourcemap: true, + }, + plugins: [ + rust({ + cargoArgs: [ + // This enables multi-threading + "--config", `build.rustflags=["-C", "target-feature=+atomics,+bulk-memory,+mutable-globals", "-C", "link-arg=--max-memory=4294967296"]`, + "--no-default-features", + "--features", "browser", + "-Z", "build-std=panic_abort,std", + ], + + experimental: { + typescriptDeclarationDir: "dist/crates", + }, + }), + ], +}; diff --git a/wasm/rust-toolchain.toml b/wasm/rust-toolchain.toml new file mode 100644 index 000000000..b67e839e6 --- /dev/null +++ b/wasm/rust-toolchain.toml @@ -0,0 +1,4 @@ +[toolchain] +channel = "nightly-2023-05-24" +components = [ "rust-std", "rust-src" ] +targets = [ "wasm32-unknown-unknown" ] diff --git a/wasm/src/lib.rs b/wasm/src/lib.rs index 04479514f..39d99851a 100644 --- a/wasm/src/lib.rs +++ b/wasm/src/lib.rs @@ -163,13 +163,17 @@ pub use record::*; pub(crate) mod types; +#[cfg(not(test))] +mod thread_pool; + use wasm_bindgen::prelude::*; +#[cfg(not(test))] +use thread_pool::ThreadPool; + use std::str::FromStr; use crate::types::RecordPlaintextNative; -#[cfg(feature = "parallel")] -pub use wasm_bindgen_rayon::init_thread_pool; // Facilities for cross-platform logging in both web browsers and nodeJS #[wasm_bindgen] @@ -201,3 +205,20 @@ impl Credits for RecordPlaintextNative { } } } + + +#[cfg(not(test))] +pub use thread_pool::initialize_worker; + +#[cfg(not(test))] +#[wasm_bindgen(js_name = "initThreadPool")] +pub async fn init_thread_pool(url: web_sys::Url, num_threads: usize) -> Result<(), JsValue> { + console_error_panic_hook::set_once(); + + ThreadPool::builder() + .url(url) + .num_threads(num_threads) + .build_global().await?; + + Ok(()) +} diff --git a/wasm/src/thread_pool/mod.rs b/wasm/src/thread_pool/mod.rs new file mode 100644 index 000000000..8e2098a80 --- /dev/null +++ b/wasm/src/thread_pool/mod.rs @@ -0,0 +1,180 @@ +// Copyright (C) 2019-2023 Aleo Systems Inc. +// This file is part of the Aleo SDK library. + +// The Aleo SDK library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// The Aleo SDK library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with the Aleo SDK library. If not, see . + +use wasm_bindgen::prelude::*; +use wasm_bindgen_futures::JsFuture; +use rayon::ThreadBuilder; +use futures::future::try_join_all; +use std::future::Future; +use spmc::{channel, Sender, Receiver}; + + +#[wasm_bindgen(inline_js = r###" + export function spawnWorker(url, module, memory, address) { + return new Promise((resolve) => { + const worker = new Worker(url, { + type: "module", + }); + + worker.addEventListener("message", (event) => { + resolve(worker); + }, { + capture: true, + once: true, + }); + + worker.postMessage({ + module, + memory, + address, + }); + }); + } +"###)] +extern "C" { + #[wasm_bindgen(js_name = spawnWorker)] + fn spawn_worker( + url: &web_sys::Url, + module: &JsValue, + memory: &JsValue, + address: *const Receiver, + ) -> js_sys::Promise; +} + + +async fn spawn_workers(url: web_sys::Url, num_threads: usize) -> Result, JsValue> { + let module = wasm_bindgen::module(); + let memory = wasm_bindgen::memory(); + + let (sender, receiver) = channel(); + + let receiver = Box::leak(Box::new(receiver)); + + let workers = try_join_all((0..num_threads).map(|_| { + JsFuture::from(spawn_worker(&url, &module, &memory, receiver)) + })).await?; + + // Needed to work around a Firefox bug where Workers get garbage collected too early + // https://bugzilla.mozilla.org/show_bug.cgi?id=1592227 + std::mem::forget(workers); + + Ok(sender) +} + +async fn spawn_local_thread_pool(url: web_sys::Url, num_threads: usize) -> Result { + let pool; + + if num_threads == 1 { + pool = rayon::ThreadPoolBuilder::new() + .num_threads(1) + .use_current_thread() + .build() + .unwrap_throw(); + + } else { + let mut sender = spawn_workers(url, num_threads).await?; + + pool = rayon::ThreadPoolBuilder::new() + .num_threads(num_threads) + .spawn_handler(move |thread| { + sender.send(thread).unwrap_throw(); + Ok(()) + }) + .build() + .unwrap_throw(); + } + + Ok(pool) +} + +async fn spawn_global_thread_pool(url: web_sys::Url, num_threads: usize) -> Result<(), JsValue> { + if num_threads == 1 { + rayon::ThreadPoolBuilder::new() + .num_threads(1) + .use_current_thread() + .build_global() + .unwrap_throw(); + + } else { + let mut sender = spawn_workers(url, num_threads).await?; + + rayon::ThreadPoolBuilder::new() + .num_threads(num_threads) + .spawn_handler(move |thread| { + sender.send(thread).unwrap_throw(); + Ok(()) + }) + .build_global() + .unwrap_throw(); + } + + Ok(()) +} + + +pub struct ThreadPool { + url: Option, + num_threads: Option, +} + +impl ThreadPool { + pub fn builder() -> Self { + Self { + url: None, + num_threads: None, + } + } + + pub fn url(mut self, url: web_sys::Url) -> Self { + self.url = Some(url); + self + } + + pub fn num_threads(mut self, num_threads: usize) -> Self { + self.num_threads = Some(num_threads); + self + } + + fn defaults(self) -> (web_sys::Url, usize) { + ( + self.url.expect("Missing url for ThreadPool"), + + self.num_threads.unwrap_or_else(|| { + let window: web_sys::Window = js_sys::global().unchecked_into(); + window.navigator().hardware_concurrency() as usize + }), + ) + } + + // TODO this should cleanup the receiver when the ThreadPool is dropped + pub fn build_local(self) -> impl Future> { + let (url, num_threads) = self.defaults(); + spawn_local_thread_pool(url, num_threads) + } + + pub fn build_global(self) -> impl Future> { + let (url, num_threads) = self.defaults(); + spawn_global_thread_pool(url, num_threads) + } +} + + +#[wasm_bindgen(js_name = initializeWorker)] +pub fn initialize_worker(receiver: *const Receiver) where Receiver: Sync { + // This is safe because it uses `Box::leak` so the Receiver lives forever + let receiver = unsafe { &*receiver }; + receiver.recv().unwrap_throw().run(); +}