diff --git a/.circleci/config.yml b/.circleci/config.yml index 395b5623f..0f1b52640 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,13 +2,13 @@ version: 2.1 orbs: - node: circleci/node@5.1.0 + node: circleci/node@5.2.0 executors: rust-node: docker: - - image: cimg/rust:1.73-node + - image: cimg/rust:1.80-node commands: @@ -73,6 +73,25 @@ jobs: yarn test + e2e-testnet: + executor: rust-node + steps: + - setup-sdk + - run: + working_directory: sdk/e2e/testnet + command: | + yarn start + + e2e-mainnet: + executor: rust-node + steps: + - setup-sdk + - run: + working_directory: sdk/e2e/mainnet + command: | + yarn start + + template-node: executor: rust-node steps: @@ -119,7 +138,8 @@ jobs: - run: working_directory: wasm command: | - cargo clippy + cargo clippy --features testnet + cargo clippy --features mainnet check-fmt: executor: rust-node @@ -144,6 +164,12 @@ workflows: - sdk-test: requires: - sdk + - e2e-testnet: + requires: + - sdk + - e2e-mainnet: + requires: + - sdk - template-node: requires: - sdk diff --git a/.github/ISSUE_TEMPLATE/bug.md b/.github/ISSUE_TEMPLATE/bug.md index 7f7e62f59..032dfbb64 100644 --- a/.github/ISSUE_TEMPLATE/bug.md +++ b/.github/ISSUE_TEMPLATE/bug.md @@ -10,7 +10,7 @@ labels: bug diff --git a/.gitignore b/.gitignore index c3036429c..3b93409d1 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ **/node_modules **/target **/dist +**/tmp storage*/ **/.next @@ -18,4 +19,4 @@ rust/src/program/.DS_Store # Local Netlify folder .netlify -package-lock.json \ No newline at end of file +package-lock.json diff --git a/README.md b/README.md index 963a9b082..12e3fbd2c 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ several TypeScript & JavaScript libraries which provide the following functional 4. [Management of program state and data](https://provable.tools/record) 5. [Communication with the Aleo network](https://provable.tools/rest) -All of this functionality is demonstrated on [Provable.tools](https://provable.tools). +All of this functionality is demonstrated on [Provable.tools](https://provable.tools). The Aleo SDK is divided into three TypeScript/JavaScript packages: @@ -29,7 +29,7 @@ The official Aleo SDK providing JavaScript/TypeScript tools for creating zero-kn ### ⚡ Build your own app -Start here with the [Aleo SDK Readme](https://github.com/ProvableHQ/sdk#readme) to get started building your +Start here with the [Aleo SDK Readme](https://github.com/ProvableHQ/sdk#readme) to get started building your first zero-knowledge web app. #### Source: [`Aleo SDK`](https://www.npmjs.com/package/@provablehq/sdk) @@ -47,7 +47,7 @@ start with working examples should start here. Create Leo App Aleo-Wasm -Aleo Wasm is a Rust crate which compiles the Aleo source code responsible for creating and executing zero-knowledge programs into +Aleo Wasm is a Rust crate which compiles the Aleo source code responsible for creating and executing zero-knowledge programs into WebAssembly. When compiled with `wasm-pack`, JavaScript bindings are generated for the WebAssembly allowing Aleo zero-knowledge programs to be used in the browser and Node.js. This package is available on NPM (linked above). The Aleo Wasm diff --git a/create-leo-app/template-react-leo/README.md b/create-leo-app/template-react-leo/README.md index 14e510447..2b7d4c1f9 100644 --- a/create-leo-app/template-react-leo/README.md +++ b/create-leo-app/template-react-leo/README.md @@ -40,7 +40,7 @@ Your app should be running on http://localhost:5173/ ## Deploy program from web app -> [!WARNING] +> [!WARNING] > This is for demonstration purposes or local testing only, in production applications you > should avoid building a public facing web app with private key information @@ -62,7 +62,7 @@ Aleo programs deployed require unique names, make sure to edit the program's nam 2. (Optional) Provide a fee record manually (located in commented code within `worker.js`) If you do not provide a manual fee record, the SDK will attempt to scan for a record starting at the latest block. A simple way to speed this up would be to make a public transaction to this account right before deploying. - + 3. Run the web app and hit the deploy button ## Production deployment diff --git a/create-leo-app/template-react-leo/src/App.jsx b/create-leo-app/template-react-leo/src/App.jsx index b41f64e40..426144c3a 100644 --- a/create-leo-app/template-react-leo/src/App.jsx +++ b/create-leo-app/template-react-leo/src/App.jsx @@ -46,7 +46,7 @@ function App() { return ( <>
- + Aleo logo diff --git a/create-leo-app/template-react-leo/src/workers/worker.js b/create-leo-app/template-react-leo/src/workers/worker.js index 8f8a86b59..a9b75bbc0 100644 --- a/create-leo-app/template-react-leo/src/workers/worker.js +++ b/create-leo-app/template-react-leo/src/workers/worker.js @@ -37,7 +37,7 @@ async function deployProgram(program) { keyProvider.useCache(true); // Create a record provider that will be used to find records and transaction data for Aleo programs - const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1"); + const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1"); // Use existing account with funds const account = new Account({ @@ -48,7 +48,7 @@ async function deployProgram(program) { // Initialize a program manager to talk to the Aleo network with the configured key and record providers const programManager = new ProgramManager( - "https://api.explorer.aleo.org/v1", + "https://api.explorer.provable.com/v1", keyProvider, recordProvider, ); diff --git a/create-leo-app/template-react-managed-worker/src/App.jsx b/create-leo-app/template-react-managed-worker/src/App.jsx index f8504eb67..f7238fad7 100644 --- a/create-leo-app/template-react-managed-worker/src/App.jsx +++ b/create-leo-app/template-react-managed-worker/src/App.jsx @@ -36,7 +36,7 @@ function App() { return ( <>
- + Aleo logo diff --git a/create-leo-app/template-react-ts/README.md b/create-leo-app/template-react-ts/README.md index b571c81ea..58eaffffc 100644 --- a/create-leo-app/template-react-ts/README.md +++ b/create-leo-app/template-react-ts/README.md @@ -40,7 +40,7 @@ Your app should be running on http://localhost:5173/ ## Deploy program from web app -> [!WARNING] +> [!WARNING] > This is for demonstration purposes or local testing only, in production applications you > should avoid building a public facing web app with private key information @@ -62,7 +62,7 @@ Aleo programs deployed require unique names, make sure to edit the program's nam 2. (Optional) Provide a fee record manually (located in commented code within `worker.js`) If you do not provide a manual fee record, the SDK will attempt to scan for a record starting at the latest block. A simple way to speed this up would be to make a public transaction to this account right before deploying. - + 3. Run the web app and hit the deploy button ## Production deployment diff --git a/create-leo-app/template-react-ts/src/App.tsx b/create-leo-app/template-react-ts/src/App.tsx index 4dab329d4..7f13cbf93 100644 --- a/create-leo-app/template-react-ts/src/App.tsx +++ b/create-leo-app/template-react-ts/src/App.tsx @@ -46,7 +46,7 @@ function App() { return ( <>
- + Aleo logo diff --git a/create-leo-app/template-react-ts/src/workers/worker.ts b/create-leo-app/template-react-ts/src/workers/worker.ts index 125003604..2c5d00d2f 100644 --- a/create-leo-app/template-react-ts/src/workers/worker.ts +++ b/create-leo-app/template-react-ts/src/workers/worker.ts @@ -38,7 +38,7 @@ async function deployProgram(program) { keyProvider.useCache(true); // Create a record provider that will be used to find records and transaction data for Aleo programs - const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1"); + const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1"); // Use existing account with funds const account = new Account({ @@ -49,7 +49,7 @@ async function deployProgram(program) { // Initialize a program manager to talk to the Aleo network with the configured key and record providers const programManager = new ProgramManager( - "https://api.explorer.aleo.org/v1", + "https://api.explorer.provable.com/v1", keyProvider, recordProvider, ); diff --git a/create-leo-app/template-vanilla/main.js b/create-leo-app/template-vanilla/main.js index 6cd15b13e..9dd482d13 100644 --- a/create-leo-app/template-vanilla/main.js +++ b/create-leo-app/template-vanilla/main.js @@ -29,7 +29,7 @@ document.querySelector("#app").innerHTML = ` - + diff --git a/create-leo-app/template-vanilla/worker.js b/create-leo-app/template-vanilla/worker.js index cead94590..ec3502529 100644 --- a/create-leo-app/template-vanilla/worker.js +++ b/create-leo-app/template-vanilla/worker.js @@ -45,7 +45,7 @@ async function deployProgram(program) { keyProvider.useCache(true); // Create a record provider that will be used to find records and transaction data for Aleo programs - const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1"); + const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1"); // Use existing account with funds const account = new Account({ @@ -56,7 +56,7 @@ async function deployProgram(program) { // Initialize a program manager to talk to the Aleo network with the configured key and record providers const programManager = new ProgramManager( - "https://api.explorer.aleo.org/v1", + "https://api.explorer.provable.com/v1", keyProvider, recordProvider, ); @@ -91,5 +91,5 @@ onmessage = async function (e) { postMessage({ error: error.message }); } } - + }; diff --git a/package.json b/package.json index 6c3110fc8..612fd6f76 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,9 @@ "wasm", "website", "create-leo-app", - "create-leo-app/*" + "create-leo-app/*", + "e2e", + "e2e/*" ], "type": "module", "scripts": { diff --git a/sdk/README.md b/sdk/README.md index 2b1dd30c8..e1df1ba3c 100644 --- a/sdk/README.md +++ b/sdk/README.md @@ -275,7 +275,7 @@ import { Account, AleoNetworkClient, NetworkRecordProvider, ProgramManager, Aleo const account = new Account(); // Create a network client to connect to the Aleo network -const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1"); +const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1"); // Create a key provider that will be used to find public proving & verifying keys for Aleo programs const keyProvider = new AleoKeyProvider(); @@ -285,7 +285,7 @@ keyProvider.useCache = true; const recordProvider = new NetworkRecordProvider(account, networkClient); // Initialize a program manager to talk to the Aleo network with the configured key and record providers -const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider); +const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider); // Set the account for the program manager programManager.setAccount(account); @@ -367,7 +367,7 @@ const keyProvider = new AleoKeyProvider(); keyProvider.useCache(true); // Create a record provider that will be used to find records and transaction data for Aleo programs -const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1"); +const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1"); // Use existing account with funds const account = new Account({ @@ -377,7 +377,7 @@ const account = new Account({ const recordProvider = new NetworkRecordProvider(account, networkClient); // Initialize a program manager to talk to the Aleo network with the configured key and record providers -const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider); +const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider); programManager.setAccount(account) // Define an Aleo program to deploy @@ -429,7 +429,7 @@ A full example of this implementation can be found [here](https://github.com/Pro Aleo Credits are used to access blockspace and computational resources on the network, with users paying Credits to submit transactions and have them processed. -Aleo credits are defined in the [credits.aleo](https://explorer.aleo.org/program/credits.aleo) program. This program is +Aleo credits are defined in the [credits.aleo](https://explorer.provable.com/program/credits.aleo) program. This program is deployed to the Aleo network and defines data structures representing Aleo credits and the functions used to manage them. There are two ways to hold Aleo credits: @@ -544,13 +544,13 @@ import { Account, ProgramManager, AleoKeyProvider, NetworkRecordProvider, AleoNe // Create a new NetworkClient, KeyProvider, and RecordProvider const account = Account.from_string({privateKey: "user1PrivateKey"}); -const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1"); +const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1"); const keyProvider = new AleoKeyProvider(); const recordProvider = new NetworkRecordProvider(account, networkClient); // Initialize a program manager with the key provider to automatically fetch keys for executions const USER_1_ADDRESS = "user1Address"; -const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider); +const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider); programManager.setAccount(account); // Send a private transfer to yourself @@ -585,7 +585,7 @@ assert(public_balance === 0); As shown above, a public balance of any address can be checked with `getMappingValue` function of the `NetworkClient`. ```typescript -const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1"); +const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1"); const USER_1_ADDRESS = "user1Address"; const public_balance = networkClient.getMappingValue("credits.aleo", USER_1_ADDRESS); ``` @@ -674,13 +674,13 @@ import { Account, ProgramManager, AleoKeyProvider, NetworkRecordProvider, AleoNe // Create a new NetworkClient, KeyProvider, and RecordProvider const account = Account.from_string({privateKey: "user1PrivateKey"}); -const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1"); +const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1"); const keyProvider = new AleoKeyProvider(); const recordProvider = new NetworkRecordProvider(account, networkClient); // Initialize a program manager with the key provider to automatically fetch keys for executions const USER_2_ADDRESS = "user2Address"; -const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider); +const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider); programManager.setAccount(account); /// Send private transfer to User 2 @@ -695,12 +695,12 @@ import { Account, ProgramManager, AleoKeyProvider, NetworkRecordProvider, AleoNe // Create a new NetworkClient, KeyProvider, and RecordProvider const account = Account.from_string({privateKey: "user2PrivateKey"}); -const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1"); +const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1"); const keyProvider = new AleoKeyProvider(); const recordProvider_User2 = new NetworkRecordProvider(account, networkClient); // Initialize a program manager with the key provider to automatically fetch keys for executions -const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider); +const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider); programManager.setAccount(account); // Fetch the transaction from the network that user 1 sent @@ -863,7 +863,7 @@ read the value of a specific key within a mapping. ```typescript import { AleoNetworkClient } from '@provablehq/sdk'; -const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1"); +const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1"); const creditsMappings = networkClient.getMappings("credits.aleo"); assert(creditsMappings === ["account"]); @@ -903,20 +903,20 @@ by the Aleo network. All that the user of the SDK must do is ensure that the inp If function inputs are invalid, the network will return an error, but the fee paid for the transaction will still be consumed. Therefore, it is important to ensure that the inputs to a function are valid before executing it. -A simple example of a mapping update can be shown by simply executing 'transfer_public` as shown below. +A simple example of a mapping update can be shown by simply executing `transfer_public` as shown below. ```typescript import { Account, ProgramManager, AleoKeyProvider, NetworkRecordProvider, AleoNetworkClient } from '@provablehq/sdk'; // Create a new NetworkClient, KeyProvider, and RecordProvider const account = Account.from_string({privateKey: "user1PrivateKey"}); -const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1"); +const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1"); const keyProvider = new AleoKeyProvider(); const recordProvider = new NetworkRecordProvider(account, networkClient); // Initialize a program manager with the key provider to automatically fetch keys for executions const RECIPIENT_ADDRESS = "user1Address"; -const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider); +const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider); programManager.setAccount(account); // Update or initialize a public balance diff --git a/sdk/e2e/mainnet/index.js b/sdk/e2e/mainnet/index.js new file mode 100644 index 000000000..e8b3c103f --- /dev/null +++ b/sdk/e2e/mainnet/index.js @@ -0,0 +1,59 @@ +import {Account, initThreadPool, ProgramManager, AleoKeyProvider, AleoKeyProviderParams} from "@provablehq/sdk/mainnet.js"; + +await initThreadPool(); + +const programName = "hello_hello.aleo" + +const hello_hello_program =` +program ${programName}; + +function hello: + input r0 as u32.public; + input r1 as u32.private; + add r0 r1 into r2; + output r2 as u32.private;` + +async function localProgramExecution(program, programName, aleoFunction, inputs) { + const programManager = new ProgramManager(); + + // Create a temporary account for the execution of the program + const account = new Account(); + programManager.setAccount(account); + + // Create a key provider in order to re-use the same key for each execution + const keyProvider = new AleoKeyProvider(); + keyProvider.useCache(true); + programManager.setKeyProvider(keyProvider); + + // Pre-synthesize the program keys and then cache them in memory using key provider + const keyPair = await programManager.synthesizeKeys(hello_hello_program, aleoFunction, inputs); + programManager.keyProvider.cacheKeys(`${programName}:${aleoFunction}`, keyPair); + + // Specify parameters for the key provider to use search for program keys. In particular specify the cache key + // that was used to cache the keys in the previous step. + const keyProviderParams = new AleoKeyProviderParams({cacheKey: `${programName}:${aleoFunction}`}); + + // Execute once using the key provider params defined above. This will use the cached proving keys and make + // execution significantly faster. + let executionResponse = await programManager.run( + program, + aleoFunction, + inputs, + true, + undefined, + keyProviderParams, + ); + console.log("hello_hello/hello executed - result:", executionResponse.getOutputs()); + + // Verify the execution using the verifying key that was generated earlier. + if (programManager.verifyExecution(executionResponse)) { + console.log("hello_hello/hello execution verified!"); + } else { + throw("Execution failed verification!"); + } +} + +const start = Date.now(); +console.log("Starting execute!"); +await localProgramExecution(hello_hello_program, programName, "hello", ["5u32", "5u32"]); +console.log("Execute finished!", Date.now() - start); diff --git a/sdk/e2e/mainnet/package.json b/sdk/e2e/mainnet/package.json new file mode 100644 index 000000000..76b07025a --- /dev/null +++ b/sdk/e2e/mainnet/package.json @@ -0,0 +1,12 @@ +{ + "name": "e2e-mainnet", + "private": true, + "version": "0.0.0", + "type": "module", + "scripts": { + "start": "node index.js" + }, + "dependencies": { + "@provablehq/sdk": "^0.6.0" + } +} diff --git a/sdk/e2e/testnet/index.js b/sdk/e2e/testnet/index.js new file mode 100644 index 000000000..7cacddfd9 --- /dev/null +++ b/sdk/e2e/testnet/index.js @@ -0,0 +1,59 @@ +import {Account, initThreadPool, ProgramManager, AleoKeyProvider, AleoKeyProviderParams} from "@provablehq/sdk/testnet.js"; + +await initThreadPool(); + +const programName = "hello_hello.aleo" + +const hello_hello_program =` +program ${programName}; + +function hello: + input r0 as u32.public; + input r1 as u32.private; + add r0 r1 into r2; + output r2 as u32.private;` + +async function localProgramExecution(program, programName, aleoFunction, inputs) { + const programManager = new ProgramManager(); + + // Create a temporary account for the execution of the program + const account = new Account(); + programManager.setAccount(account); + + // Create a key provider in order to re-use the same key for each execution + const keyProvider = new AleoKeyProvider(); + keyProvider.useCache(true); + programManager.setKeyProvider(keyProvider); + + // Pre-synthesize the program keys and then cache them in memory using key provider + const keyPair = await programManager.synthesizeKeys(hello_hello_program, aleoFunction, inputs); + programManager.keyProvider.cacheKeys(`${programName}:${aleoFunction}`, keyPair); + + // Specify parameters for the key provider to use search for program keys. In particular specify the cache key + // that was used to cache the keys in the previous step. + const keyProviderParams = new AleoKeyProviderParams({cacheKey: `${programName}:${aleoFunction}`}); + + // Execute once using the key provider params defined above. This will use the cached proving keys and make + // execution significantly faster. + let executionResponse = await programManager.run( + program, + aleoFunction, + inputs, + true, + undefined, + keyProviderParams, + ); + console.log("hello_hello/hello executed - result:", executionResponse.getOutputs()); + + // Verify the execution using the verifying key that was generated earlier. + if (programManager.verifyExecution(executionResponse)) { + console.log("hello_hello/hello execution verified!"); + } else { + throw("Execution failed verification!"); + } +} + +const start = Date.now(); +console.log("Starting execute!"); +await localProgramExecution(hello_hello_program, programName, "hello", ["5u32", "5u32"]); +console.log("Execute finished!", Date.now() - start); diff --git a/sdk/e2e/testnet/package.json b/sdk/e2e/testnet/package.json new file mode 100644 index 000000000..4ae49ff3d --- /dev/null +++ b/sdk/e2e/testnet/package.json @@ -0,0 +1,12 @@ +{ + "name": "e2e-testnet", + "private": true, + "version": "0.0.0", + "type": "module", + "scripts": { + "start": "node index.js" + }, + "dependencies": { + "@provablehq/sdk": "^0.6.0" + } +} diff --git a/sdk/jest-config.json b/sdk/jest-config.json deleted file mode 100644 index 57191f39f..000000000 --- a/sdk/jest-config.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "transform": { - "^.+\\.(t|j)sx?$": ["ts-jest", { "useESM": true, "tsconfig": "tsconfig.test.json" }] - }, - "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", - "moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"], - - "preset": "ts-jest/presets/default-esm" -} diff --git a/sdk/jest-integration-config.json b/sdk/jest-integration-config.json deleted file mode 100644 index 1b279a785..000000000 --- a/sdk/jest-integration-config.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "transform": { - "^.+\\.(t|j)sx?$": ["ts-jest", { "useESM": true, "tsconfig": "tsconfig.test.json" }] - }, - "testRegex": "(/__tests__/.*|(\\.|/)(integration))\\.(jsx?|tsx?)$", - "moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"], - - "preset": "ts-jest/presets/default-esm" -} diff --git a/sdk/package.json b/sdk/package.json index adb0d5938..006297cc4 100644 --- a/sdk/package.json +++ b/sdk/package.json @@ -7,12 +7,20 @@ ], "license": "GPL-3.0", "type": "module", - "main": "./dist/node.js", - "browser": "./dist/index.js", + "main": "./dist/testnet/node.js", + "browser": "./dist/testnet/browser.js", "exports": { ".": { - "node": "./dist/node.js", - "default": "./dist/index.js" + "node": "./dist/testnet/node.js", + "default": "./dist/testnet/browser.js" + }, + "./testnet.js": { + "node": "./dist/testnet/node.js", + "default": "./dist/testnet/browser.js" + }, + "./mainnet.js": { + "node": "./dist/mainnet/node.js", + "default": "./dist/mainnet/browser.js" } }, "files": [ @@ -23,9 +31,7 @@ "scripts": { "build": "rimraf dist && rollup -c rollup.config.js", "prepublish": "yarn build", - "test": "node --no-warnings --experimental-vm-modules ../node_modules/jest/bin/jest.js --config jest-config.json --detectOpenHandles", - "integration": "node --no-warnings --experimental-vm-modules ../node_modules/jest/bin/jest.js --silent=false --runInBand --detectOpenHandles", - "clear_jest": "jest --clearCache" + "test": "rimraf tmp && rollup -c rollup.test.js && mocha tmp/**/*.test.js --parallel --timeout 60000" }, "repository": { "type": "git", @@ -49,24 +55,28 @@ }, "devDependencies": { "@rollup/plugin-replace": "^5.0.5", - "@types/jest": "^29.5.5", + "@types/chai": "^4.3.16", "@types/mime": "^3.0.1", + "@types/mocha": "^10.0.7", + "@types/sinon": "^17.0.3", "@typescript-eslint/eslint-plugin": "^5.41.0", "@typescript-eslint/parser": "^5.41.0", "better-docs": "^2.7.2", + "chai": "^5.1.1", "clean-jsdoc-theme": "^4.1.8", "core-js": "^3.38.1", "cpr": "^3.0.1", "eslint": "^8.26.0", "eslint-config-prettier": "^8.5.0", "eslint-plugin-import": "^2.26.0", - "jest": "^29.7.0", + "glob": "^10.4.5", "jsdoc": "^3.6.11", + "mocha": "^10.7.0", "prettier": "2.7.1", "rimraf": "^5.0.1", "rollup": "^3.27.2", "rollup-plugin-typescript2": "^0.36.0", - "ts-jest": "^29.1.1", + "sinon": "^18.0.0", "typescript": "^5.2.2" } } diff --git a/sdk/rollup.config.js b/sdk/rollup.config.js index c4238869a..b430f4a7c 100644 --- a/sdk/rollup.config.js +++ b/sdk/rollup.config.js @@ -2,39 +2,50 @@ import typescript from "rollup-plugin-typescript2"; import replace from "@rollup/plugin-replace"; import $package from "./package.json" assert { type: "json" }; -export default { - input: { - index: "./src/index.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", - "comlink", - "@provablehq/wasm", - ], - plugins: [ - replace({ - preventAssignment: true, - delimiters: ['', ''], - values: { - '%%VERSION%%': $package.version, - }, - }), - typescript({ - tsconfig: "tsconfig.json", - clean: true, - }), - ], -}; +const networks = [ + "testnet", + "mainnet", +]; + +export default networks.map((network) => { + return { + input: { + "node-polyfill": "./src/node-polyfill.ts", + "browser": "./src/browser.ts", + "worker": "./src/worker.ts", + "node": "./src/node.ts", + }, + output: { + dir: `dist/${network}`, + format: "es", + sourcemap: true, + }, + external: [ + // Used by node-polyfill + "node:worker_threads", + "node:os", + "node:fs", + "node:crypto", + "mime/lite.js", + "sync-request", + + // Used by the SDK + "comlink", + `@provablehq/wasm/${network}.js`, + ], + plugins: [ + replace({ + preventAssignment: true, + delimiters: ['', ''], + values: { + '%%VERSION%%': $package.version, + '%%NETWORK%%': network, + }, + }), + typescript({ + tsconfig: "tsconfig.json", + clean: true, + }), + ], + }; +}); diff --git a/sdk/rollup.test.js b/sdk/rollup.test.js new file mode 100644 index 000000000..57d7bb08b --- /dev/null +++ b/sdk/rollup.test.js @@ -0,0 +1,58 @@ +import typescript from "rollup-plugin-typescript2"; +import replace from "@rollup/plugin-replace"; +import { globSync } from "glob"; +import $package from "./package.json" assert { type: "json" }; + +const networks = [ + "testnet", + "mainnet", +]; + +function inputs() { + const files = {}; + + globSync("./tests/**/*.ts").forEach((x) => { + files[x.replace(/\.[^\.]+$/, "")] = x; + }); + + return files; +} + +export default networks.map((network) => { + return { + input: inputs(), + output: { + dir: `tmp/${network}`, + chunkFileNames: "[name].js", + format: "es", + sourcemap: true, + }, + external: [ + // Used by node-polyfill + "node:worker_threads", + "node:os", + "node:fs", + "node:crypto", + "mime/lite.js", + "sync-request", + + // Used by the SDK + "comlink", + `@provablehq/wasm/${network}.js`, + ], + plugins: [ + replace({ + preventAssignment: true, + delimiters: ['', ''], + values: { + '%%VERSION%%': $package.version, + '%%NETWORK%%': network, + }, + }), + typescript({ + tsconfig: "tsconfig.test.json", + clean: true, + }), + ], + }; +}); diff --git a/sdk/src/account.ts b/sdk/src/account.ts index 053239b3b..961734e45 100644 --- a/sdk/src/account.ts +++ b/sdk/src/account.ts @@ -5,7 +5,7 @@ import { ViewKey, PrivateKeyCiphertext, RecordCiphertext, -} from "./index"; +} from "./browser"; interface AccountParam { privateKey?: string; @@ -149,7 +149,7 @@ export class Account { * * @example * // Create a connection to the Aleo network and an account - * const connection = new NodeConnection("vm.aleo.org/api"); + * const connection = new AleoNetworkClient("https://api.explorer.provable.com/v1"); * const account = Account.fromCiphertext("ciphertext", "password"); * * // Get a record from the network diff --git a/sdk/src/index.ts b/sdk/src/browser.ts similarity index 97% rename from sdk/src/index.ts rename to sdk/src/browser.ts index 9db96416d..3448378ef 100644 --- a/sdk/src/index.ts +++ b/sdk/src/browser.ts @@ -1,5 +1,5 @@ import "./polyfill/shared"; -import {VerifyingKey, Metadata} from "@provablehq/wasm"; +import {VerifyingKey, Metadata} from "@provablehq/wasm/%%NETWORK%%.js"; const KEY_STORE = Metadata.baseUrl(); @@ -168,7 +168,7 @@ export { ViewKey, initThreadPool, verifyFunctionExecution, -} from "@provablehq/wasm"; +} from "@provablehq/wasm/%%NETWORK%%.js"; export { initializeWasm }; diff --git a/sdk/src/function-key-provider.ts b/sdk/src/function-key-provider.ts index 76cd24de0..97288ab47 100644 --- a/sdk/src/function-key-provider.ts +++ b/sdk/src/function-key-provider.ts @@ -9,7 +9,7 @@ import { PUBLIC_TRANSFER, PUBLIC_TO_PRIVATE_TRANSFER, PUBLIC_TRANSFER_AS_SIGNER -} from "./index"; +} from "./browser"; import { get } from "./utils"; type FunctionKeyPair = [ProvingKey, VerifyingKey]; @@ -142,11 +142,11 @@ interface FunctionKeyProvider { * * * const keyProvider = new AleoKeyProvider(); - * const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1"); + * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1"); * const recordProvider = new NetworkRecordProvider(account, networkClient); * * // Initialize a program manager with the key provider to automatically fetch keys for value transfers - * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider); + * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider); * programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5); * * // Keys can also be fetched manually @@ -191,12 +191,12 @@ interface FunctionKeyProvider { * * @example * // Create a new object which implements the KeyProvider interface - * const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1"); + * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1"); * const keyProvider = new AleoKeyProvider(); * const recordProvider = new NetworkRecordProvider(account, networkClient); * * // Initialize a program manager with the key provider to automatically fetch keys for value transfers - * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider); + * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider); * programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5); * * // Keys can also be fetched manually @@ -314,12 +314,12 @@ class AleoKeyProvider implements FunctionKeyProvider { * * @example * // Create a new object which implements the KeyProvider interface - * const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1"); + * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1"); * const keyProvider = new AleoKeyProvider(); * const recordProvider = new NetworkRecordProvider(account, networkClient); * * // Initialize a program manager with the key provider to automatically fetch keys for value transfers - * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider); + * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider); * programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5); * * // Keys can also be fetched manually using the key provider @@ -370,12 +370,12 @@ class AleoKeyProvider implements FunctionKeyProvider { * * @example * // Create a new AleoKeyProvider object - * const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1"); + * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1"); * const keyProvider = new AleoKeyProvider(); * const recordProvider = new NetworkRecordProvider(account, networkClient); * * // Initialize a program manager with the key provider to automatically fetch keys for value transfers - * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider); + * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider); * programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5); * * // Keys can also be fetched manually @@ -484,12 +484,12 @@ class AleoKeyProvider implements FunctionKeyProvider { * * @example * // Create a new AleoKeyProvider - * const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1"); + * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1"); * const keyProvider = new AleoKeyProvider(); * const recordProvider = new NetworkRecordProvider(account, networkClient); * * // Initialize a program manager with the key provider to automatically fetch keys for value transfers - * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider); + * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider); * programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5); * * // Keys can also be fetched manually diff --git a/sdk/src/network-client.ts b/sdk/src/network-client.ts index 72a76af90..5f8349033 100644 --- a/sdk/src/network-client.ts +++ b/sdk/src/network-client.ts @@ -9,7 +9,7 @@ import { Transaction, TransactionModel, logAndThrow -} from "./index"; +} from "./browser"; type ProgramImports = { [key: string]: string | Program }; @@ -27,7 +27,7 @@ interface AleoNetworkClientOptions { * const localNetworkClient = new AleoNetworkClient("http://localhost:3030"); * * // Connection to a public beacon node - * const publicnetworkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1"); + * const publicnetworkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1"); */ class AleoNetworkClient { host: string; @@ -35,7 +35,7 @@ class AleoNetworkClient { account: Account | undefined; constructor(host: string, options?: AleoNetworkClientOptions) { - this.host = host + "/testnet"; + this.host = host + "/%%NETWORK%%"; if (options && options.headers) { this.headers = options.headers; @@ -77,7 +77,7 @@ class AleoNetworkClient { * @param host */ setHost(host: string) { - this.host = host + "/testnet"; + this.host = host + "/%%NETWORK%%"; } async fetchData( diff --git a/sdk/src/node.ts b/sdk/src/node.ts index 6aadbc294..b94eab757 100644 --- a/sdk/src/node.ts +++ b/sdk/src/node.ts @@ -1,2 +1,2 @@ import "./node-polyfill"; -export * from "./index"; +export * from "./browser"; diff --git a/sdk/src/offline-key-provider.ts b/sdk/src/offline-key-provider.ts index 5beadefed..377f8f917 100644 --- a/sdk/src/offline-key-provider.ts +++ b/sdk/src/offline-key-provider.ts @@ -11,7 +11,7 @@ import { PUBLIC_TRANSFER, PUBLIC_TO_PRIVATE_TRANSFER, PUBLIC_TRANSFER_AS_SIGNER -} from "./index"; +} from "./browser"; /** * Search parameters for the offline key provider. This class implements the KeySearchParams interface and includes @@ -195,7 +195,7 @@ class OfflineSearchParams implements KeySearchParams { * const offlineExecuteTx = await this.buildExecutionTransaction("hello_hello.aleo", "hello", 1, false, ["5u32", "5u32"], undefined, offlineSearchParams, undefined, undefined, undefined, undefined, offlineQuery, program); * * // Broadcast the transaction later on a machine with internet access - * const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1"); + * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1"); * const txId = await networkClient.broadcastTransaction(offlineExecuteTx); */ class OfflineKeyProvider implements FunctionKeyProvider { diff --git a/sdk/src/program-manager.ts b/sdk/src/program-manager.ts index 81fcec408..748ded5f3 100644 --- a/sdk/src/program-manager.ts +++ b/sdk/src/program-manager.ts @@ -3,6 +3,7 @@ import { AleoKeyProvider, AleoNetworkClient, ExecutionResponse, + FunctionExecution, FunctionKeyProvider, FunctionKeyPair, OfflineQuery, @@ -20,8 +21,7 @@ import { VALID_TRANSFER_TYPES, logAndThrow, ProgramManagerBase as WasmProgramManager, verifyFunctionExecution, AleoKeyProviderParams, CREDITS_PROGRAM_KEYS, -} from "./index"; -import {Execution} from "@provablehq/wasm/dist/crates/aleo_wasm"; +} from "./browser"; /** * Represents the options for executing a transaction in the Aleo network. @@ -76,7 +76,7 @@ class ProgramManager { * @param { RecordProvider | undefined } recordProvider A record provider that implements {@link RecordProvider} interface */ constructor(host?: string | undefined, keyProvider?: FunctionKeyProvider | undefined, recordProvider?: RecordProvider | undefined) { - this.host = host ? host : 'https://api.explorer.aleo.org/v1'; + this.host = host ? host : 'https://api.explorer.provable.com/v1'; this.networkClient = new AleoNetworkClient(this.host); this.keyProvider = keyProvider ? keyProvider : new AleoKeyProvider(); @@ -134,13 +134,13 @@ class ProgramManager { * * @example * // Create a new NetworkClient, KeyProvider, and RecordProvider - * const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1"); + * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1"); * const keyProvider = new AleoKeyProvider(); * const recordProvider = new NetworkRecordProvider(account, networkClient); * * // Initialize a program manager with the key provider to automatically fetch keys for deployments * const program = "program hello_hello.aleo;\n\nfunction 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"; - * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider); + * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider); * * // Define a fee in credits * const fee = 1.2; @@ -223,13 +223,13 @@ class ProgramManager { * * @example * // Create a new NetworkClient, KeyProvider, and RecordProvider using official Aleo record, key, and network providers - * const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1"); + * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1"); * const keyProvider = new AleoKeyProvider(); * keyProvider.useCache = true; * const recordProvider = new NetworkRecordProvider(account, networkClient); * * // Initialize a program manager with the key provider to automatically fetch keys for executions - * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider); + * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider); * * // Build and execute the transaction * const transaction = await programManager.buildExecutionTransaction({ @@ -330,13 +330,13 @@ class ProgramManager { * * @example * // Create a new NetworkClient, KeyProvider, and RecordProvider using official Aleo record, key, and network providers - * const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1"); + * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1"); * const keyProvider = new AleoKeyProvider(); * keyProvider.useCache = true; * const recordProvider = new NetworkRecordProvider(account, networkClient); * * // Initialize a program manager with the key provider to automatically fetch keys for executions - * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider); + * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider); * * // Build and execute the transaction * const transaction = await programManager.execute({ @@ -502,13 +502,13 @@ class ProgramManager { * * @example * // Create a new NetworkClient, KeyProvider, and RecordProvider - * const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1"); + * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1"); * const keyProvider = new AleoKeyProvider(); * const recordProvider = new NetworkRecordProvider(account, networkClient); * * // Initialize a program manager with the key provider to automatically fetch keys for executions * const programName = "hello_hello.aleo"; - * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider); + * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider); * const record = "{ owner: aleo184vuwr5u7u0ha5f5k44067dd2uaqewxx6pe5ltha5pv99wvhfqxqv339h4.private, microcredits: 45000000u64.private, _nonce: 4106205762862305308495708971985748592380064201230396559307556388725936304984group.public}" * const tx_id = await programManager.split(25000000, record); * const transaction = await programManager.networkClient.getTransaction(tx_id); @@ -607,13 +607,13 @@ class ProgramManager { * * @example * // Create a new NetworkClient, KeyProvider, and RecordProvider - * const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1"); + * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1"); * const keyProvider = new AleoKeyProvider(); * const recordProvider = new NetworkRecordProvider(account, networkClient); * * // Initialize a program manager with the key provider to automatically fetch keys for executions * const programName = "hello_hello.aleo"; - * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider); + * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider); * await programManager.initialize(); * const tx_id = await programManager.transfer(1, "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", "private", 0.2) * const transaction = await programManager.networkClient.getTransaction(tx_id); @@ -745,12 +745,12 @@ class ProgramManager { * * @example * // Create a new NetworkClient, KeyProvider, and RecordProvider - * const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1"); + * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1"); * const keyProvider = new AleoKeyProvider(); * const recordProvider = new NetworkRecordProvider(account, networkClient); * * // Initialize a program manager with the key provider to automatically fetch keys for executions - * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider); + * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider); * await programManager.initialize(); * const tx_id = await programManager.transfer(1, "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", "private", 0.2) * const transaction = await programManager.networkClient.getTransaction(tx_id); @@ -780,7 +780,7 @@ class ProgramManager { * keyProvider.useCache = true; * * // Create a new ProgramManager with the key that will be used to bond credits - * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, undefined); + * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, undefined); * programManager.setAccount(new Account("YourPrivateKey")); * * // Create the bonding transaction object for later submission @@ -841,7 +841,7 @@ class ProgramManager { * keyProvider.useCache = true; * * // Create a new ProgramManager with the key that will be used to bond credits - * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, undefined); + * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, undefined); * programManager.setAccount(new Account("YourPrivateKey")); * * // Create the bonding transaction @@ -872,7 +872,7 @@ class ProgramManager { * keyProvider.useCache = true; * * // Create a new ProgramManager with the key that will be used to bond credits - * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, undefined); + * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, undefined); * programManager.setAccount(new Account("YourPrivateKey")); * * // Create the bond validator transaction object for later use. @@ -935,7 +935,7 @@ class ProgramManager { * keyProvider.useCache = true; * * // Create a new ProgramManager with the key that will be used to bond credits - * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, undefined); + * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, undefined); * programManager.setAccount(new Account("YourPrivateKey")); * * // Create the bonding transaction @@ -971,7 +971,7 @@ class ProgramManager { * keyProvider.useCache = true; * * // Create a new ProgramManager with the key that will be used to unbond credits. - * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, undefined); + * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, undefined); * const tx = await programManager.buildUnbondPublicTransaction("aleo1jx8s4dvjepculny4wfrzwyhs3tlyv65r58ns3g6q2gm2esh7ps8sqy9s5j", 2000000); * console.log(tx); * @@ -1018,7 +1018,7 @@ class ProgramManager { * keyProvider.useCache = true; * * // Create a new ProgramManager with the key that will be used to bond credits - * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, undefined); + * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, undefined); * programManager.setAccount(new Account("YourPrivateKey")); * * // Create the bonding transaction and send it to the network @@ -1052,7 +1052,7 @@ class ProgramManager { * keyProvider.useCache = true; * * // Create a new ProgramManager with the key that will be used to claim unbonded credits. - * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, undefined); + * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, undefined); * * // Create the claim unbonded transaction object for later use. * const tx = await programManager.buildClaimUnbondPublicTransaction("aleo1jx8s4dvjepculny4wfrzwyhs3tlyv65r58ns3g6q2gm2esh7ps8sqy9s5j"); @@ -1100,7 +1100,7 @@ class ProgramManager { * keyProvider.useCache = true; * * // Create a new ProgramManager with the key that will be used to bond credits - * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, undefined); + * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, undefined); * programManager.setAccount(new Account("YourPrivateKey")); * * // Create the bonding transaction @@ -1132,7 +1132,7 @@ class ProgramManager { * keyProvider.useCache = true; * * // Create a new ProgramManager with the key that will be used to bond credits - * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, undefined); + * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, undefined); * programManager.setAccount(new Account("ValidatorPrivateKey")); * * // Create the bonding transaction @@ -1190,7 +1190,7 @@ class ProgramManager { * keyProvider.useCache = true; * * // Create a new ProgramManager with the key that will be used to bond credits - * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, undefined); + * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, undefined); * programManager.setAccount(new Account("ValidatorPrivateKey")); * * // Create the bonding transaction @@ -1213,7 +1213,7 @@ class ProgramManager { */ verifyExecution(executionResponse: ExecutionResponse): boolean { try { - const execution = executionResponse.getExecution(); + const execution = executionResponse.getExecution(); const function_id = executionResponse.getFunctionId(); const program = executionResponse.getProgram(); const verifyingKey = executionResponse.getVerifyingKey(); diff --git a/sdk/src/record-provider.ts b/sdk/src/record-provider.ts index a59df7108..7acade552 100644 --- a/sdk/src/record-provider.ts +++ b/sdk/src/record-provider.ts @@ -1,4 +1,4 @@ -import { logAndThrow, RecordPlaintext } from "./index"; +import { logAndThrow, RecordPlaintext } from "./browser"; import { Account } from "./account"; import { AleoNetworkClient } from "./network-client"; @@ -38,7 +38,7 @@ interface RecordProvider { * * // When the program manager is initialized with the record provider it will be used to find automatically find * // fee records and amount records for value transfers so that they do not need to be specified manually - * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider); + * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider); * programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5); */ findCreditsRecord(microcredits: number, unspent: boolean, nonces?: string[], searchParameters?: RecordSearchParams): Promise; @@ -64,7 +64,7 @@ interface RecordProvider { * * // When the program manager is initialized with the record provider it will be used to find automatically find * // fee records and amount records for value transfers so that they do not need to be specified manually - * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider); + * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider); * programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5); */ findCreditsRecords(microcreditAmounts: number[], unspent: boolean, nonces?: string[], searchParameters?: RecordSearchParams): Promise; @@ -169,7 +169,7 @@ class NetworkRecordProvider implements RecordProvider { * * @example * // Create a new NetworkRecordProvider - * const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1"); + * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1"); * const keyProvider = new AleoKeyProvider(); * const recordProvider = new NetworkRecordProvider(account, networkClient); * @@ -182,7 +182,7 @@ class NetworkRecordProvider implements RecordProvider { * * // When the program manager is initialized with the record provider it will be used to find automatically find * // fee records and amount records for value transfers so that they do not need to be specified manually - * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider); + * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider); * programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5); * * */ @@ -225,7 +225,7 @@ class NetworkRecordProvider implements RecordProvider { * * @example * // Create a new NetworkRecordProvider - * const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1"); + * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1"); * const keyProvider = new AleoKeyProvider(); * const recordProvider = new NetworkRecordProvider(account, networkClient); * @@ -238,7 +238,7 @@ class NetworkRecordProvider implements RecordProvider { * * // When the program manager is initialized with the record provider it will be used to find automatically find * // fee records and amount records for value transfers so that they do not need to be specified manually - * const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider); + * const programManager = new ProgramManager("https://api.explorer.provable.com/v1", keyProvider, recordProvider); * programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5); */ async findCreditsRecord(microcredits: number, unspent: boolean, nonces?: string[], searchParameters?: RecordSearchParams): Promise { @@ -281,7 +281,7 @@ class NetworkRecordProvider implements RecordProvider { * const params = new BlockHeightSearch(89995, 99995); * * // Create a new NetworkRecordProvider - * const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1"); + * const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1"); * const keyProvider = new AleoKeyProvider(); * const recordProvider = new NetworkRecordProvider(account, networkClient); * diff --git a/sdk/src/worker.ts b/sdk/src/worker.ts index 862bbebc6..df9be76bf 100644 --- a/sdk/src/worker.ts +++ b/sdk/src/worker.ts @@ -1,11 +1,11 @@ import "./polyfill/shared"; -import {initThreadPool, ProgramManager, PrivateKey, verifyFunctionExecution, FunctionKeyPair} from "./index"; +import {initThreadPool, ProgramManager, PrivateKey, verifyFunctionExecution, FunctionKeyPair} from "./browser"; import { AleoKeyProvider, AleoKeyProviderParams} from "./function-key-provider"; import { expose } from "comlink"; await initThreadPool(); -const defaultHost = "https://api.explorer.aleo.org/v1"; +const defaultHost = "https://api.explorer.provable.com/v1"; const keyProvider = new AleoKeyProvider(); const programManager = new ProgramManager( defaultHost, diff --git a/sdk/tests/account.test.ts b/sdk/tests/account.test.ts index 3d3ae9bb3..a0474758a 100644 --- a/sdk/tests/account.test.ts +++ b/sdk/tests/account.test.ts @@ -1,67 +1,71 @@ -import {jest} from '@jest/globals' -import { Account, Address, PrivateKey, RecordCiphertext, ViewKey } from '../src/node' -import { seed, message, beaconPrivateKeyString, beaconViewKeyString, beaconAddressString, recordCiphertextString, foreignCiphertextString, recordPlaintextString } from './data/account-data'; - +import sinon from "sinon"; +import { expect } from "chai"; +import { Account, Address, PrivateKey, RecordCiphertext, ViewKey } from "../src/node"; +import { seed, message, beaconPrivateKeyString, beaconViewKeyString, beaconAddressString, recordCiphertextString, foreignCiphertextString, recordPlaintextString } from "./data/account-data"; describe('Account', () => { + afterEach(() => { + sinon.restore(); + }); + describe('constructors', () => { - test('creates a new account if no parameters are passed', () => { + it('creates a new account if no parameters are passed', () => { // Generate account from rng const account = new Account(); // Test object member type consistency - expect(account._privateKey).toBeInstanceOf(PrivateKey); - expect(account._viewKey).toBeInstanceOf(ViewKey); - expect(account._address).toBeInstanceOf(Address); + expect(account._privateKey).instanceof(PrivateKey); + expect(account._viewKey).instanceof(ViewKey); + expect(account._address).instanceof(Address); // Test convenience method type consistency - expect(account.privateKey()).toBeInstanceOf(PrivateKey); - expect(account.viewKey()).toBeInstanceOf(ViewKey); - expect(account.address()).toBeInstanceOf(Address); + expect(account.privateKey()).instanceof(PrivateKey); + expect(account.viewKey()).instanceof(ViewKey); + expect(account.address()).instanceof(Address); }); - test('creates a new from seed', () => { + it('creates a new from seed', () => { // Generate account from a seed const account = new Account({seed: seed}); // Test object member type consistency - expect(account._privateKey).toBeInstanceOf(PrivateKey); - expect(account._viewKey).toBeInstanceOf(ViewKey); - expect(account._address).toBeInstanceOf(Address); + expect(account._privateKey).instanceof(PrivateKey); + expect(account._viewKey).instanceof(ViewKey); + expect(account._address).instanceof(Address); // Test convenience method type consistency - expect(account.privateKey()).toBeInstanceOf(PrivateKey); - expect(account.viewKey()).toBeInstanceOf(ViewKey); - expect(account.address()).toBeInstanceOf(Address); + expect(account.privateKey()).instanceof(PrivateKey); + expect(account.viewKey()).instanceof(ViewKey); + expect(account.address()).instanceof(Address); // Test that expected output is generated - expect(account.privateKey().to_string()).toEqual(beaconPrivateKeyString); - expect(account.viewKey().to_string()).toEqual(beaconViewKeyString); - expect(account.address().to_string()).toEqual(beaconAddressString); - expect(account.toString()).toEqual(beaconAddressString); + expect(account.privateKey().to_string()).equal(beaconPrivateKeyString); + expect(account.viewKey().to_string()).equal(beaconViewKeyString); + expect(account.address().to_string()).equal(beaconAddressString); + expect(account.toString()).equal(beaconAddressString); }); - test('throws an error if parameters are invalid', () => { - expect(() => new Account({privateKey: 'invalidPrivateKey'})).toThrow(); + it('throws an error if parameters are invalid', () => { + expect(() => new Account({privateKey: 'invalidPrivateKey'})).throw(); }); - test('creates an account object from a valid private key string', () => { + it('creates an account object from a valid private key string', () => { // Generate account from valid private key string const account = new Account( {privateKey: beaconPrivateKeyString}); // Test object member type consistency - expect(account._privateKey).toBeInstanceOf(PrivateKey); - expect(account._viewKey).toBeInstanceOf(ViewKey); - expect(account._address).toBeInstanceOf(Address); + expect(account._privateKey).instanceof(PrivateKey); + expect(account._viewKey).instanceof(ViewKey); + expect(account._address).instanceof(Address); // Test convenience method type consistency - expect(account.privateKey()).toBeInstanceOf(PrivateKey); - expect(account.viewKey()).toBeInstanceOf(ViewKey); - expect(account.address()).toBeInstanceOf(Address); + expect(account.privateKey()).instanceof(PrivateKey); + expect(account.viewKey()).instanceof(ViewKey); + expect(account.address()).instanceof(Address); // Test that expected output is generated - expect(account.privateKey().to_string()).toEqual(beaconPrivateKeyString); - expect(account.viewKey().to_string()).toEqual(beaconViewKeyString); - expect(account.address().to_string()).toEqual(beaconAddressString); - expect(account.toString()).toEqual(beaconAddressString); + expect(account.privateKey().to_string()).equal(beaconPrivateKeyString); + expect(account.viewKey().to_string()).equal(beaconViewKeyString); + expect(account.address().to_string()).equal(beaconAddressString); + expect(account.toString()).equal(beaconAddressString); }); - test('can encrypt an account and decrypt to the same account', () => { + it('can encrypt an account and decrypt to the same account', () => { const newAccount = new Account(); const privateKeyCiphertext = newAccount.encryptAccount("mypassword"); const privateKeyCiphertextString = privateKeyCiphertext.toString(); @@ -72,14 +76,14 @@ describe('Account', () => { for (const account of [accountFromString, accountFromObject]) { // Test that expected output is generated - expect(account.privateKey().to_string()).toEqual(newAccount.privateKey().to_string()); - expect(account.viewKey().to_string()).toEqual(newAccount.viewKey().to_string()); - expect(account.address().to_string()).toEqual(newAccount.toString()); - expect(account.toString()).toEqual(newAccount.toString()); + expect(account.privateKey().to_string()).equal(newAccount.privateKey().to_string()); + expect(account.viewKey().to_string()).equal(newAccount.viewKey().to_string()); + expect(account.address().to_string()).equal(newAccount.toString()); + expect(account.toString()).equal(newAccount.toString()); } }); - test('fails to create an account from a bad password', () => { + it('fails to create an account from a bad password', () => { const newAccount = new Account(); const privateKeyCiphertext = newAccount.encryptAccount("mypassword"); const privateKeyCiphertextString = privateKeyCiphertext.toString(); @@ -89,28 +93,30 @@ describe('Account', () => { Account.fromCiphertext(privateKeyCiphertext, "badpassword"); // Should not get here - expect(true).toBe(false); + expect(true).equal(false); } catch (err) { // The account should fail to decrypt - expect(true).toBe(true); + expect(true).equal(true); } }); }); describe('View Key Record Decryption', () => { - test('decrypts a record in ciphertext form', () => { + it('decrypts a record in ciphertext form', () => { const account = new Account({privateKey: "APrivateKey1zkpJkyYRGYtkeHDaFfwsKtUJzia7csiWhfBWPXWhXJzy9Ls"}); - const decrypt_spy = jest.spyOn(account._viewKey, 'decrypt'); + + const decrypt_spy = sinon.spy(account._viewKey, 'decrypt'); + // Decrypt record the private key owns const decryptedRecord = account.decryptRecord(recordCiphertextString); // Ensure the underlying wasm is being called with the right data - expect(decrypt_spy).toHaveBeenCalledWith(recordCiphertextString); + expect(decrypt_spy.calledWith(recordCiphertextString)).equal(true); // Ensure it decrypts to the correct data - expect(decryptedRecord).toBe(recordPlaintextString); + expect(decryptedRecord).equal(recordPlaintextString); }); - test('doesnt decrypt records from other accounts nor identifies them as the record owner', () => { + it('doesnt decrypt records from other accounts nor identifies them as the record owner', () => { function tryDecrypt() { try { return account.decryptRecord(foreignCiphertextString); @@ -119,62 +125,63 @@ describe('Account', () => { } } const account = new Account({privateKey: "APrivateKey1zkpJkyYRGYtkeHDaFfwsKtUJzia7csiWhfBWPXWhXJzy9Ls"}); - const decrypt_spy = jest.spyOn(account._viewKey, 'decrypt'); + const decrypt_spy = sinon.spy(account._viewKey, 'decrypt'); const recordCiphertext = RecordCiphertext.fromString(foreignCiphertextString); // Ensure a foreign record decryption attempt throws - expect(tryDecrypt).toThrow(); + expect(tryDecrypt).throw(); // Ensure the underlying wasm is being called with the right data - expect(decrypt_spy).toHaveBeenCalledWith(foreignCiphertextString); + expect(decrypt_spy.calledWith(foreignCiphertextString)).equal(true); // Ensure the account doesn't identify the record ciphertext as its own from both string and object forms - expect(account.ownsRecordCiphertext(foreignCiphertextString)).toBe(false); - expect(account.ownsRecordCiphertext(recordCiphertext)).toBe(false); + expect(account.ownsRecordCiphertext(foreignCiphertextString)).equal(false); + expect(account.ownsRecordCiphertext(recordCiphertext)).equal(false); }); - test('decrypts an array of records in ciphertext form', () => { + it('decrypts an array of records in ciphertext form', () => { const account = new Account({privateKey: "APrivateKey1zkpJkyYRGYtkeHDaFfwsKtUJzia7csiWhfBWPXWhXJzy9Ls"}); const ciphertexts = [recordCiphertextString, recordCiphertextString]; - const decrypt_spy = jest.spyOn(account._viewKey, 'decrypt'); + const decrypt_spy = sinon.spy(account._viewKey, 'decrypt'); const decryptedRecords = account.decryptRecords(ciphertexts); // Ensure the right number of calls were called and right inputs were passed - expect(decrypt_spy).toHaveBeenCalledTimes(2); - expect(decrypt_spy).toHaveBeenCalledWith(ciphertexts[0]); - expect(decrypt_spy).toHaveBeenCalledWith(ciphertexts[1]); + expect(decrypt_spy.callCount).equal(2); + expect(decrypt_spy.calledWith(ciphertexts[0])).equal(true); + expect(decrypt_spy.calledWith(ciphertexts[1])).equal(true); // Ensure the records were decrypted to the correct data - expect(decryptedRecords).toEqual([recordPlaintextString, recordPlaintextString]); + expect(decryptedRecords).deep.equal([recordPlaintextString, recordPlaintextString]); }); }); describe('Sign and Verify', () => { - test("verifies the signature on a message", () => { + it("verifies the signature on a message", () => { const account = new Account(); const other_message = Uint8Array.from([104, 101, 108, 108, 111, 32, 120, 121, 114, 108, 99]); - const sign_spy = jest.spyOn(account._privateKey, 'sign'); + const sign_spy = sinon.spy(account._privateKey, 'sign'); const signature = account.sign(message); // Ensure the signature was called with the right message - expect(sign_spy).lastCalledWith(message); + expect(sign_spy.calledWith(message)).equal(true); const other_signature = account.sign(other_message); // Ensure the signature was called with the right message and the right number of times - expect(sign_spy).lastCalledWith(other_message); - expect(sign_spy).toHaveBeenCalledTimes(2); - const verify_spy = jest.spyOn(account._address, 'verify'); + expect(sign_spy.calledWith(other_message)).equal(true); + expect(sign_spy.callCount).equal(2); + + const verify_spy = sinon.spy(account._address, 'verify'); const isValid = account.verify(message, signature); - expect(verify_spy).lastCalledWith(message, signature); + expect(verify_spy.calledWith(message, signature)).equal(true); const isSigValidForWrongMessage = account.verify(other_message, signature); - expect(verify_spy).lastCalledWith(other_message, signature); + expect(verify_spy.calledWith(other_message, signature)).equal(true); const isSigValidForMultipleMessages = account.verify(other_message, other_signature); - expect(verify_spy).lastCalledWith(other_message, other_signature); - expect(verify_spy).toHaveBeenCalledTimes(3); + expect(verify_spy.calledWith(other_message, other_signature)).equal(true); + expect(verify_spy.callCount).equal(3); // Ensure the signature was valid - expect(isValid).toBe(true); + expect(isValid).equal(true); // Ensure the second message was valid - expect(isSigValidForMultipleMessages).toBe(true); + expect(isSigValidForMultipleMessages).equal(true); // Ensure a signature & message mismatch is invalid - expect(isSigValidForWrongMessage).toBe(false); + expect(isSigValidForWrongMessage).equal(false); }); }); }); diff --git a/sdk/tests/key-provider.test.ts b/sdk/tests/key-provider.test.ts index 3d50f7e8b..d3bc18c8f 100644 --- a/sdk/tests/key-provider.test.ts +++ b/sdk/tests/key-provider.test.ts @@ -1,6 +1,5 @@ +import { expect } from "chai"; import {AleoKeyProvider, CachedKeyPair, CREDITS_PROGRAM_KEYS, FunctionKeyPair, OfflineKeyProvider, ProvingKey, VerifyingKey} from "../src/node"; -import {jest} from '@jest/globals' -jest.retryTimes(1); describe('KeyProvider', () => { let keyProvider: AleoKeyProvider; @@ -16,38 +15,40 @@ describe('KeyProvider', () => { try { const keys = await keyProvider.transferKeys("invalid"); // This should never be reached - expect(true).toBe(false); + expect(true).equal(false); } catch (e) { - expect(e).toBeInstanceOf(Error); + expect(e).instanceof(Error); } - }, 60000); + }); it('Should use cache when set and not use it when not', async () => { // Ensure the cache properly downloads and stores keys keyProvider.useCache(true); + const [provingKey, verifyingKey] = await keyProvider.feePublicKeys(); - expect(keyProvider.cache.size).toBe(1); - expect(provingKey).toBeInstanceOf(ProvingKey); - expect(verifyingKey).toBeInstanceOf(VerifyingKey); + expect(keyProvider.cache.size).equal(1); + expect(provingKey).instanceof(ProvingKey); + expect(verifyingKey).instanceof(VerifyingKey); + const transferCacheKey = keyProvider.cache.keys().next().value; - const [cachedProvingKey, cachedVerifyingKey] = keyProvider.cache.get(transferCacheKey); - expect(cachedProvingKey).toBeInstanceOf(Uint8Array); - expect(cachedVerifyingKey).toBeInstanceOf(Uint8Array); + const [cachedProvingKey, cachedVerifyingKey] = keyProvider.cache.get(transferCacheKey!); + expect(cachedProvingKey).instanceof(Uint8Array); + expect(cachedVerifyingKey).instanceof(Uint8Array); // Ensure the functionKeys method to get the keys and that the cache is used to do so const [fetchedProvingKey, fetchedVerifyingKey] = await keyProvider.fetchCreditsKeys(CREDITS_PROGRAM_KEYS.fee_public) - expect(keyProvider.cache.size).toBe(1); - expect(fetchedProvingKey).toBeInstanceOf(ProvingKey); - expect(fetchedVerifyingKey).toBeInstanceOf(VerifyingKey); + expect(keyProvider.cache.size).equal(1); + expect(fetchedProvingKey).instanceof(ProvingKey); + expect(fetchedVerifyingKey).instanceof(VerifyingKey); // Clear the cache and turn it off to ensure the keys are re-downloaded and the cache is not used keyProvider.clearCache(); keyProvider.useCache(false); const [redownloadedProvingKey, redownloadedVerifyingKey] = await keyProvider.feePublicKeys(); - expect(keyProvider.cache.size).toBe(0); - expect(redownloadedProvingKey).toBeInstanceOf(ProvingKey); - expect(redownloadedVerifyingKey).toBeInstanceOf(VerifyingKey); - }, 200000); + expect(keyProvider.cache.size).equal(0); + expect(redownloadedProvingKey).instanceof(ProvingKey); + expect(redownloadedVerifyingKey).instanceof(VerifyingKey); + }); it.skip("Should not fetch offline keys that haven't already been stored", async () => { // Download the credits.aleo function keys @@ -92,53 +93,52 @@ describe('KeyProvider', () => { const [unbondPublicProverLocal, unbondPublicVerifierLocal] = await offlineKeyProvider.unBondPublicKeys(); // Ensure the checksum of the recovered keys match those of the original keys - expect(bondPublicProver.checksum()).toEqual(bondPublicProverLocal.checksum()); - expect(bondPublicVerifier.checksum()).toEqual(bondPublicVerifierLocal.checksum()); - expect(claimUnbondPublicProver.checksum()).toEqual(claimUnbondPublicProverLocal.checksum()); - expect(claimUnbondVerifier.checksum()).toEqual(claimUnbondVerifierLocal.checksum()); - expect(feePrivateProver.checksum()).toEqual(feePrivateProverLocal.checksum()); - expect(feePrivateVerifier.checksum()).toEqual(feePrivateVerifierLocal.checksum()); - expect(feePublicProver.checksum()).toEqual(feePublicProverLocal.checksum()); - expect(feePublicVerifier.checksum()).toEqual(feePublicVerifierLocal.checksum()); - expect(joinProver.checksum()).toEqual(joinProverLocal.checksum()); - expect(joinVerifier.checksum()).toEqual(joinVerifierLocal.checksum()); - expect(splitProver.checksum()).toEqual(splitProverLocal.checksum()); - expect(splitVerifier.checksum()).toEqual(splitVerifierLocal.checksum()); - expect(transferPrivateProver.checksum()).toEqual(transferPrivateProverLocal.checksum()); - expect(transferPrivateVerifier.checksum()).toEqual(transferPrivateVerifierLocal.checksum()); - expect(transferPrivateToPublicProver.checksum()).toEqual(transferPrivateToPublicProverLocal.checksum()); - expect(transferPrivateToPublicVerifier.checksum()).toEqual(transferPrivateToPublicVerifierLocal.checksum()); - expect(transferPublicProver.checksum()).toEqual(transferPublicProverLocal.checksum()); - expect(transferPublicVerifier.checksum()).toEqual(transferPublicVerifierLocal.checksum()); - expect(transferPublicToPrivateProver.checksum()).toEqual(transferPublicToPrivateProverLocal.checksum()); - expect(transferPublicToPrivateVerifier.checksum()).toEqual(transferPublicToPrivateVerifierLocal.checksum()); - expect(unbondPublicProver.checksum()).toEqual(unbondPublicProverLocal.checksum()); - expect(unbondPublicVerifier.checksum()).toEqual(unbondPublicVerifierLocal.checksum()); + expect(bondPublicProver.checksum()).equal(bondPublicProverLocal.checksum()); + expect(bondPublicVerifier.checksum()).equal(bondPublicVerifierLocal.checksum()); + expect(claimUnbondPublicProver.checksum()).equal(claimUnbondPublicProverLocal.checksum()); + expect(claimUnbondVerifier.checksum()).equal(claimUnbondVerifierLocal.checksum()); + expect(feePrivateProver.checksum()).equal(feePrivateProverLocal.checksum()); + expect(feePrivateVerifier.checksum()).equal(feePrivateVerifierLocal.checksum()); + expect(feePublicProver.checksum()).equal(feePublicProverLocal.checksum()); + expect(feePublicVerifier.checksum()).equal(feePublicVerifierLocal.checksum()); + expect(joinProver.checksum()).equal(joinProverLocal.checksum()); + expect(joinVerifier.checksum()).equal(joinVerifierLocal.checksum()); + expect(splitProver.checksum()).equal(splitProverLocal.checksum()); + expect(splitVerifier.checksum()).equal(splitVerifierLocal.checksum()); + expect(transferPrivateProver.checksum()).equal(transferPrivateProverLocal.checksum()); + expect(transferPrivateVerifier.checksum()).equal(transferPrivateVerifierLocal.checksum()); + expect(transferPrivateToPublicProver.checksum()).equal(transferPrivateToPublicProverLocal.checksum()); + expect(transferPrivateToPublicVerifier.checksum()).equal(transferPrivateToPublicVerifierLocal.checksum()); + expect(transferPublicProver.checksum()).equal(transferPublicProverLocal.checksum()); + expect(transferPublicVerifier.checksum()).equal(transferPublicVerifierLocal.checksum()); + expect(transferPublicToPrivateProver.checksum()).equal(transferPublicToPrivateProverLocal.checksum()); + expect(transferPublicToPrivateVerifier.checksum()).equal(transferPublicToPrivateVerifierLocal.checksum()); + expect(unbondPublicProver.checksum()).equal(unbondPublicProverLocal.checksum()); + expect(unbondPublicVerifier.checksum()).equal(unbondPublicVerifierLocal.checksum()); // Ensure the recovered keys are of the correct type - expect(bondPublicProverLocal.isBondPublicProver()).toEqual(true); - expect(bondPublicVerifierLocal.isBondPublicVerifier()).toEqual(true); - expect(claimUnbondPublicProverLocal.isClaimUnbondPublicProver()).toEqual(true); - expect(claimUnbondVerifierLocal.isClaimUnbondPublicVerifier()).toEqual(true); - expect(feePrivateProverLocal.isFeePrivateProver()).toEqual(true); - expect(feePrivateVerifierLocal.isFeePrivateVerifier()).toEqual(true); - expect(feePublicProverLocal.isFeePublicProver()).toEqual(true); - expect(feePublicVerifierLocal.isFeePublicVerifier()).toEqual(true); - expect(joinProverLocal.isJoinProver()).toEqual(true); - expect(joinVerifierLocal.isJoinVerifier()).toEqual(true); - expect(splitProverLocal.isSplitProver()).toEqual(true); - expect(splitVerifierLocal.isSplitVerifier()).toEqual(true); - expect(transferPrivateProverLocal.isTransferPrivateProver()).toEqual(true); - expect(transferPrivateVerifierLocal.isTransferPrivateVerifier()).toEqual(true); - expect(transferPrivateToPublicProverLocal.isTransferPrivateToPublicProver()).toEqual(true); - expect(transferPrivateToPublicVerifierLocal.isTransferPrivateToPublicVerifier()).toEqual(true); - expect(transferPublicProverLocal.isTransferPublicProver()).toEqual(true); - expect(transferPublicVerifierLocal.isTransferPublicVerifier()).toEqual(true); - expect(transferPublicToPrivateProverLocal.isTransferPublicToPrivateProver()).toEqual(true); - expect(transferPublicToPrivateVerifierLocal.isTransferPublicToPrivateVerifier()).toEqual(true); - expect(unbondPublicProverLocal.isUnbondPublicProver()).toEqual(true); - expect(unbondPublicVerifierLocal.isUnbondPublicVerifier()).toEqual(true); - - }, 380000); + expect(bondPublicProverLocal.isBondPublicProver()).equal(true); + expect(bondPublicVerifierLocal.isBondPublicVerifier()).equal(true); + expect(claimUnbondPublicProverLocal.isClaimUnbondPublicProver()).equal(true); + expect(claimUnbondVerifierLocal.isClaimUnbondPublicVerifier()).equal(true); + expect(feePrivateProverLocal.isFeePrivateProver()).equal(true); + expect(feePrivateVerifierLocal.isFeePrivateVerifier()).equal(true); + expect(feePublicProverLocal.isFeePublicProver()).equal(true); + expect(feePublicVerifierLocal.isFeePublicVerifier()).equal(true); + expect(joinProverLocal.isJoinProver()).equal(true); + expect(joinVerifierLocal.isJoinVerifier()).equal(true); + expect(splitProverLocal.isSplitProver()).equal(true); + expect(splitVerifierLocal.isSplitVerifier()).equal(true); + expect(transferPrivateProverLocal.isTransferPrivateProver()).equal(true); + expect(transferPrivateVerifierLocal.isTransferPrivateVerifier()).equal(true); + expect(transferPrivateToPublicProverLocal.isTransferPrivateToPublicProver()).equal(true); + expect(transferPrivateToPublicVerifierLocal.isTransferPrivateToPublicVerifier()).equal(true); + expect(transferPublicProverLocal.isTransferPublicProver()).equal(true); + expect(transferPublicVerifierLocal.isTransferPublicVerifier()).equal(true); + expect(transferPublicToPrivateProverLocal.isTransferPublicToPrivateProver()).equal(true); + expect(transferPublicToPrivateVerifierLocal.isTransferPublicToPrivateVerifier()).equal(true); + expect(unbondPublicProverLocal.isUnbondPublicProver()).equal(true); + expect(unbondPublicVerifierLocal.isUnbondPublicVerifier()).equal(true); + }); }); }); diff --git a/sdk/tests/network-client.integration.ts b/sdk/tests/network-client.integration.ts index a81a8d4fd..1cacf3ad8 100644 --- a/sdk/tests/network-client.integration.ts +++ b/sdk/tests/network-client.integration.ts @@ -1,6 +1,6 @@ +import { expect } from "chai"; import {beaconAddressString, beaconPrivateKeyString} from "./data/account-data"; -import {Account, AleoNetworkClient} from "../src"; -jest.retryTimes(3); +import {Account, AleoNetworkClient} from "../src/browser"; describe('NodeConnection', () => { let localApiClient: AleoNetworkClient; @@ -17,65 +17,64 @@ describe('NodeConnection', () => { // Integration tests to be run with a local node (run with -s flag) it('should find records', async () => { const records = await localApiClient.findUnspentRecords(0, undefined, beaconPrivateKeyString, undefined, undefined, []); - expect(Array.isArray(records)).toBe(true); + expect(Array.isArray(records)).equal(true); if (!(records instanceof Error)) { - expect(records.length).toBeGreaterThan(0); + expect(records.length).above(0); } - }, 60000); + }); it('should find records when a private key is pre-configured', async () => { const records = await remoteApiClientWithPrivateKey.findUnspentRecords(0, undefined, undefined, undefined, 100, []); - expect(Array.isArray(records)).toBe(true); + expect(Array.isArray(records)).equal(true); if (!(records instanceof Error)) { - expect(records.length).toBeGreaterThan(0); + expect(records.length).above(0); } - }, 60000); + }); it('should find records even when block height specified is higher than current block height', async () => { const records = await localApiClient.findUnspentRecords(0, 50000000000000, beaconPrivateKeyString, undefined, 100, []); - expect(Array.isArray(records)).toBe(true); + expect(Array.isArray(records)).equal(true); if (!(records instanceof Error)) { - expect(records.length).toBeGreaterThan(0); + expect(records.length).above(0); } - }, 60000); + }); it('should find records with specified amounts', async () => { let records = await localApiClient.findUnspentRecords(0, 3, beaconPrivateKeyString, [100, 200], undefined, []); - expect(Array.isArray(records)).toBe(true); + expect(Array.isArray(records)).equal(true); if (!(records instanceof Error)) { - expect(records.length).toBe(2); + expect(records.length).equal(2); } records = await localApiClient.findUnspentRecords(0, undefined, beaconPrivateKeyString, undefined, 1000, []); - expect(Array.isArray(records)).toBe(true); + expect(Array.isArray(records)).equal(true); if (!(records instanceof Error)) { - expect(records.length).toBeGreaterThan(0); + expect(records.length).above(0); } - }, 60000); + }); it('should not find records with existing nonces', async () => { const nonces: string[] = []; const records = await localApiClient.findUnspentRecords(0, 3, beaconPrivateKeyString, [100, 200], undefined, []); - expect(Array.isArray(records)).toBe(true); + expect(Array.isArray(records)).equal(true); // Find two records and store their nonces if (!(records instanceof Error)) { - expect(records.length).toBe(2); + expect(records.length).equal(2); records.forEach((record) => { nonces.push(record.nonce()); }); // Check the next records found do not have the same nonces const new_records = await localApiClient.findUnspentRecords(0, 3, beaconPrivateKeyString, [100, 200], undefined, nonces); - expect(Array.isArray(records)).toBe(true); + expect(Array.isArray(records)).equal(true); if (!(new_records instanceof Error)) { - expect(new_records.length).toBe(2); + expect(new_records.length).equal(2); new_records.forEach((record) => { - expect(nonces.includes(record.nonce())).toBe(false); + expect(nonces.includes(record.nonce())).equal(false); }); } } - - }, 60000); + }); }); }); diff --git a/sdk/tests/network-client.test.ts b/sdk/tests/network-client.test.ts index 48a7814a7..5a898a5e4 100644 --- a/sdk/tests/network-client.test.ts +++ b/sdk/tests/network-client.test.ts @@ -1,20 +1,39 @@ -import {jest} from '@jest/globals' +import sinon from "sinon"; +import { expect } from "chai"; import {Account, Block, AleoNetworkClient, TransactionModel} from "../src/node"; import {beaconAddressString, beaconPrivateKeyString} from "./data/account-data"; import {log} from "console"; -jest.retryTimes(3); + + +async function catchError(f: () => Promise): Promise { + try { + await f(); + return null; + + } catch (e) { + return e as Error; + } +} + + +async function expectThrows(f: () => Promise, message: string): Promise { + const error = await catchError(f); + expect(error).not.equal(null); + expect(error!.message).equal(message); +} + describe('NodeConnection', () => { let connection: AleoNetworkClient; - let windowFetchSpy: jest.Spied; + let windowFetchSpy: sinon.SinonSpy; beforeEach(() => { - connection = new AleoNetworkClient("https://api.explorer.aleo.org/v1"); - windowFetchSpy = jest.spyOn(globalThis, 'fetch'); + connection = new AleoNetworkClient("https://api.explorer.provable.com/v1"); + windowFetchSpy = sinon.spy(globalThis, 'fetch'); }); afterEach(() => { - jest.restoreAllMocks(); + sinon.restore(); windowFetchSpy = null as any; }); @@ -22,62 +41,71 @@ describe('NodeConnection', () => { it('should set the account property', () => { const account = new Account(); connection.setAccount(account); - expect(connection.getAccount()).toEqual(account); - }, 60000); + expect(connection.getAccount()).equal(account); + }); }); describe('getBlock', () => { - it('should return a Block object', async () => { + it.skip('should return a Block object', async () => { const block = await connection.getBlock(1); - expect((block as Block).block_hash).toEqual("ab1eddc3np4h6duwf5a7ht6u0x5maa08780l885j6xq0s7l88df0qrq3d72me"); - }, 60000); + expect((block as Block).block_hash).equal("ab1eddc3np4h6duwf5a7ht6u0x5maa08780l885j6xq0s7l88df0qrq3d72me"); + }); it('should throw an error if the request fails', async () => { - await expect(connection.getBlock(99999999)).rejects.toThrow('Error fetching block.'); - }, 60000); + await expectThrows( + () => connection.getBlock(99999999), + "Error fetching block.", + ); + }); }); describe('getBlockRange', () => { - it('should return an array of Block objects', async () => { + it.skip('should return an array of Block objects', async () => { const blockRange = await connection.getBlockRange(1, 3); - expect(Array.isArray(blockRange)).toBe(true); - expect((blockRange as Block[]).length).toBe(2); - expect(((blockRange as Block[])[0] as Block).block_hash).toBe("ab1eddc3np4h6duwf5a7ht6u0x5maa08780l885j6xq0s7l88df0qrq3d72me"); - expect(((blockRange as Block[])[1] as Block).block_hash).toBe("ab1uqmm97qk5gzhgwh6308h48aszazhfnn0xdq84lrj7e7myyrf9yyqmqdf42"); - - }, 60000); + expect(Array.isArray(blockRange)).equal(true); + expect((blockRange as Block[]).length).equal(3); + expect(((blockRange as Block[])[0] as Block).block_hash).equal("ab1eddc3np4h6duwf5a7ht6u0x5maa08780l885j6xq0s7l88df0qrq3d72me"); + expect(((blockRange as Block[])[1] as Block).block_hash).equal("ab1uqmm97qk5gzhgwh6308h48aszazhfnn0xdq84lrj7e7myyrf9yyqmqdf42"); + }); it('should throw an error if the request fails', async () => { - expect(await connection.getBlockRange(999999999, 1000000000)).toEqual([]); - }, 60000); + await expectThrows( + () => connection.getBlockRange(999999999, 1000000000), + "Error fetching blocks between 999999999 and 1000000000.", + ); + }); }); describe('getProgram', () => { it('should return a string', async () => { const program = await connection.getProgram('credits.aleo'); - expect(typeof program).toBe('string'); - }, 60000); + expect(typeof program).equal('string'); + }); it('should throw an error if the request fails', async () => { const program_id = "a" + (Math.random()).toString(32).substring(2) + ".aleo"; - await expect(connection.getProgram(program_id)).rejects.toThrow('Error fetching program'); - }, 60000); + + await expectThrows( + () => connection.getProgram(program_id), + "Error fetching program", + ); + }); }); describe('getLatestBlock', () => { it('should return a Block object', async () => { const latestBlock = await connection.getLatestBlock(); - expect(typeof (latestBlock as Block).block_hash).toBe('string'); - }, 60000); + expect(typeof (latestBlock as Block).block_hash).equal('string'); + }); it('should set the X-Aleo-SDK-Version header', async () => { - expect(windowFetchSpy.mock.calls).toStrictEqual([]); + expect(windowFetchSpy.args).deep.equal([]); await connection.getLatestBlock(); - expect(windowFetchSpy.mock.calls).toStrictEqual([ + expect(windowFetchSpy.args).deep.equal([ [ - "https://api.explorer.aleo.org/v1/testnet/latest/block", + "https://api.explorer.provable.com/v1/%%NETWORK%%/latest/block", { "headers": { // @TODO: Run the Jest tests on the compiled Rollup code, @@ -87,42 +115,45 @@ describe('NodeConnection', () => { } ], ]); - }, 60000); + }); }); describe('getLatestCommittee', () => { it('should return a string', async () => { const latestCommittee = await connection.getLatestCommittee(); - expect(typeof latestCommittee).toBe('object'); - }, 60000); + expect(typeof latestCommittee).equal('object'); + }); }); describe('getLatestHeight', () => { it('should return a number', async () => { const latestHeight = await connection.getLatestHeight(); - expect(typeof latestHeight).toBe('number'); - }, 60000); + expect(typeof latestHeight).equal('number'); + }); }); describe('getStateRoot', () => { it('should return a string', async () => { const stateRoot = await connection.getStateRoot(); - expect(typeof stateRoot).toBe('string'); - }, 60000); + expect(typeof stateRoot).equal('string'); + }); }); describe('getTransactions', () => { it('should throw an error if the request fails', async () => { - await expect(connection.getTransactions(999999999)).rejects.toThrow('Error fetching transactions.'); - }, 60000); + await expectThrows( + () => connection.getTransactions(999999999), + "Error fetching transactions.", + ); + }); }); describe('getProgramImports', () => { it('should return the correct program import names', async () => { const creditImports = await connection.getProgramImportNames("credits.aleo"); const expectedCreditImports: string[] = []; - expect(creditImports).toEqual(expectedCreditImports); - }, 60000); + expect(creditImports).deep.equal(expectedCreditImports); + }); it.skip('should return all nested imports', async () => { const imports = await connection.getProgramImports("imported_add_mul.aleo"); @@ -150,33 +181,48 @@ describe('NodeConnection', () => { ' add r0 r1 into r2;\n' + ' output r2 as u32.private;\n' }; - expect(imports).toEqual(expectedImports); - }, 60000); + expect(imports).equal(expectedImports); + }); }); describe('findUnspentRecords', () => { it('should fail if block heights or private keys are incorrectly specified', async () => { - await expect(connection.findUnspentRecords(5, 0, beaconPrivateKeyString, undefined, undefined, [])).rejects.toThrow(); - await expect(connection.findUnspentRecords(-5, 5, beaconPrivateKeyString, undefined, undefined, [])).rejects.toThrow(); - await expect(connection.findUnspentRecords(0, 5, "definitelynotaprivatekey", undefined, undefined, [])).rejects.toThrow(); - await expect(connection.findUnspentRecords(0, 5, undefined, undefined, undefined, [])).rejects.toThrow(); - }, 60000); + await expectThrows( + () => connection.findUnspentRecords(5, 0, beaconPrivateKeyString, undefined, undefined, []), + "Start height must be less than or equal to end height.", + ); + + await expectThrows( + () => connection.findUnspentRecords(-5, 5, beaconPrivateKeyString, undefined, undefined, []), + "Start height must be greater than or equal to 0", + ); + + await expectThrows( + () => connection.findUnspentRecords(0, 5, "definitelynotaprivatekey", undefined, undefined, []), + "Error parsing private key provided.", + ); + + await expectThrows( + () => connection.findUnspentRecords(0, 5, undefined, undefined, undefined, []), + "Private key must be specified in an argument to findOwnedRecords or set in the AleoNetworkClient", + ); + }); it.skip('should search a range correctly and not find records where none exist', async () => { const records = await connection.findUnspentRecords(0, 204, beaconPrivateKeyString, undefined, undefined, []); - expect(Array.isArray(records)).toBe(true); + expect(Array.isArray(records)).equal(true); if (!(records instanceof Error)) { - expect(records.length).toBe(0); + expect(records.length).equal(0); } - }, 90000); + }); }); describe('Mappings', () => { it('should find program mappings and read mappings', async () => { const mappings = await connection.getProgramMappingNames("credits.aleo"); if (!(mappings instanceof Error)) { - expect(mappings).toEqual(["committee", "delegated", "metadata", "bonded", "unbonding", "account", "withdraw"]); + expect(mappings).deep.equal(["committee", "delegated", "metadata", "bonded", "unbonding", "account", "withdraw"]); } - }, 60000); + }); }); }); diff --git a/sdk/tests/program-manager.test.ts b/sdk/tests/program-manager.test.ts index 721298b12..429ad5d7f 100644 --- a/sdk/tests/program-manager.test.ts +++ b/sdk/tests/program-manager.test.ts @@ -1,4 +1,4 @@ -import {jest} from '@jest/globals' +import { expect } from "chai"; import { beaconAddressString, helloProgram, @@ -8,18 +8,17 @@ import { stateRoot } from "./data/account-data"; import { Account, ExecutionResponse, OfflineQuery, ProgramManager, RecordPlaintext } from "../src/node"; -jest.retryTimes(3); describe('Program Manager', () => { - const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", undefined, undefined); + const programManager = new ProgramManager("https://api.explorer.provable.com/v1", undefined, undefined); programManager.setAccount(new Account({privateKey: statePathRecordOwnerPrivateKey})); describe('Execute offline', () => { it.skip('Program manager should execute offline and verify the resulting proof correctly', async () => { const execution_result = await programManager.run(helloProgram, "hello", ["5u32", "5u32"], true, undefined, undefined, undefined, undefined, undefined, undefined) - expect(execution_result.getOutputs()[0]).toEqual("10u32"); + expect(execution_result.getOutputs()[0]).equal("10u32"); programManager.verifyExecution(execution_result); - }, 1020000); + }); }); describe('Offline query', () => { @@ -32,13 +31,13 @@ describe('Program Manager', () => { const execution_result = await programManager.run(credits, "transfer_private", [statePathRecord, beaconAddressString, "5u64"], true, undefined, undefined, undefined, undefined, undefined, offlineQuery); const verified = programManager.verifyExecution(execution_result); - expect(verified).toEqual(true); - }, 1020000); + expect(verified).equal(true); + }); }); describe('Staking - Bond Public', () => { it.skip('Should execute bondPublic', async () => { // TODO - }, 420000); + }); }); -}); \ No newline at end of file +}); diff --git a/sdk/tests/record-provider.integration.ts b/sdk/tests/record-provider.integration.ts index a1963a8f3..2ca23bae2 100644 --- a/sdk/tests/record-provider.integration.ts +++ b/sdk/tests/record-provider.integration.ts @@ -1,7 +1,6 @@ -import {jest} from '@jest/globals' +import { expect } from "chai"; import { beaconPrivateKeyString } from "./data/account-data"; import { Account, AleoNetworkClient, NetworkRecordProvider, RecordPlaintext } from "../src/node"; -jest.retryTimes(3); describe('RecordProvider', () => { let account: Account; @@ -21,28 +20,28 @@ describe('RecordProvider', () => { const nonces: string[] = []; const records = await recordProvider.findCreditsRecords([100, 200], true, []); if (Array.isArray(records)) { - expect(records.length).toEqual(2); + expect(records.length).equal(2); records.forEach((record) => { nonces.push(record.nonce()); }); } else { - expect(Array.isArray(records)).toBe(true); + expect(Array.isArray(records)).equal(true); } // Get another two records with findCreditsRecords and ensure they are unique const records2 = await recordProvider.findCreditsRecords([100, 200], true, nonces); if (Array.isArray(records2)) { - expect(records2.length).toEqual(2); + expect(records2.length).equal(2); records2.forEach((record) => { - expect(nonces.includes(record.nonce())).toBe(false); + expect(nonces.includes(record.nonce())).equal(false); nonces.push(record.nonce()); }); } else { - expect(Array.isArray(records2)).toBe(true); + expect(Array.isArray(records2)).equal(true); } } catch (e) { throw e; } - }, 60000); + }); }); }); diff --git a/sdk/tests/record-provider.test.ts b/sdk/tests/record-provider.test.ts index afe810939..ad02555e3 100644 --- a/sdk/tests/record-provider.test.ts +++ b/sdk/tests/record-provider.test.ts @@ -1,16 +1,16 @@ -import {jest} from '@jest/globals' +import { expect } from "chai"; import {Account, AleoNetworkClient, BlockHeightSearch, NetworkRecordProvider} from "../src/node"; import {beaconPrivateKeyString} from "./data/account-data"; import {log} from "console"; -jest.retryTimes(3); describe.skip('RecordProvider', () => { let account: Account; let networkClient: AleoNetworkClient; let recordProvider: NetworkRecordProvider; + beforeEach(() => { account = new Account({privateKey: beaconPrivateKeyString}); - networkClient = new AleoNetworkClient("http://vm.aleo.org/api"); + networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1"); recordProvider = new NetworkRecordProvider(account, networkClient); }); @@ -19,11 +19,11 @@ describe.skip('RecordProvider', () => { const params = new BlockHeightSearch(0, 100); try { const records = await recordProvider.findCreditsRecords([100, 200], true, [], params); - expect(records).toEqual([]) + expect(records).equal([]) } catch (e) { log(e) throw e; } - }, 60000); + }); }); }); diff --git a/sdk/tests/wasm.test.ts b/sdk/tests/wasm.test.ts index 560031556..d69ddbcf1 100644 --- a/sdk/tests/wasm.test.ts +++ b/sdk/tests/wasm.test.ts @@ -1,3 +1,4 @@ +import { expect } from "chai"; import { Address, PrivateKey, ViewKey, Signature, RecordCiphertext, RecordPlaintext, PrivateKeyCiphertext } from "../src/node"; import { seed, @@ -19,9 +20,9 @@ describe('WASM Objects', () => { const address = Address.from_private_key(privateKey); // Ensure the address is an instance of Address - expect(address).toBeInstanceOf(Address); + expect(address).instanceof(Address); // Ensure the address string matches the expected value - expect(address.to_string()).toMatch(addressString); + expect(address.to_string()).string(addressString); }); it('can be constructed from view key', () => { @@ -29,18 +30,18 @@ describe('WASM Objects', () => { const address = Address.from_view_key(viewKey); // Ensure the address is an instance of Address - expect(address).toBeInstanceOf(Address); + expect(address).instanceof(Address); // Ensure the address string matches the expected value - expect(address.to_string()).toMatch(addressString); + expect(address.to_string()).string(addressString); }); it('can be constructed from an address string', () => { const address = Address.from_string(addressString); // Ensure the address is an instance of Address - expect(address).toBeInstanceOf(Address); + expect(address).instanceof(Address); // Ensure the address string matches the expected value - expect(address.to_string()).toMatch(addressString); + expect(address.to_string()).string(addressString); }); it('can verify a message signed by the correct private key', () => { @@ -50,9 +51,9 @@ describe('WASM Objects', () => { const result = address.verify(message, signature); // Ensure the result is a boolean - expect(typeof result).toBe('boolean'); + expect(typeof result).equal('boolean'); // Ensure the signature verified - expect(result).toBe(true); + expect(result).equal(true); }); it('cannot verify a message signed by the wrong private key', () => { @@ -63,9 +64,9 @@ describe('WASM Objects', () => { const result = address.verify(message, signature); // Ensure the result is a boolean - expect(typeof result).toBe('boolean'); + expect(typeof result).equal('boolean'); // Ensure the signature failed to verify - expect(result).toBe(false); + expect(result).equal(false); }); }); @@ -75,29 +76,29 @@ describe('WASM Objects', () => { const privateKey2 = new PrivateKey(); // Ensure the private key is a PrivateKey instance - expect(privateKey).toBeInstanceOf(PrivateKey); + expect(privateKey).instanceof(PrivateKey); // Ensure the private key is a PrivateKey instance - expect(privateKey2).toBeInstanceOf(PrivateKey); + expect(privateKey2).instanceof(PrivateKey); // Ensure the private keys are different - expect(privateKey.to_string()).not.toBe(privateKey2.to_string()); + expect(privateKey.to_string()).not.equal(privateKey2.to_string()); }); it('constructs properly from a seed', () => { const privateKey = PrivateKey.from_seed_unchecked(seed); // Ensure the private key is a PrivateKey instance - expect(privateKey).toBeInstanceOf(PrivateKey); + expect(privateKey).instanceof(PrivateKey); // Ensure the private key is the correct value - expect(privateKey.to_string()).toMatch(beaconPrivateKeyString); + expect(privateKey.to_string()).string(beaconPrivateKeyString); }); it('constructs properly from a private key string', () => { const privateKey = PrivateKey.from_string(privateKeyString); // Ensure the private key is a PrivateKey instance - expect(privateKey).toBeInstanceOf(PrivateKey); + expect(privateKey).instanceof(PrivateKey); // Ensure the private key is the correct value - expect(privateKey.to_string()).toMatch(privateKeyString); + expect(privateKey.to_string()).string(privateKeyString); }); it('derives the correct view key and address', () => { @@ -106,11 +107,11 @@ describe('WASM Objects', () => { const address = privateKey.to_address(); // Ensure the view key and address are the correct types - expect(viewKey).toBeInstanceOf(ViewKey); - expect(address).toBeInstanceOf(Address); + expect(viewKey).instanceof(ViewKey); + expect(address).instanceof(Address); // Ensure the view key and address are the correct values - expect(viewKey.to_string()).toMatch(viewKeyString); - expect(address.to_string()).toMatch(addressString); + expect(viewKey.to_string()).string(viewKeyString); + expect(address.to_string()).string(addressString); }); it('can construct directly to ciphertext and then decrypt to a private key', () => { @@ -119,9 +120,9 @@ describe('WASM Objects', () => { const privateKeyFromCiphertext = PrivateKey.fromPrivateKeyCiphertext(ciphertext, secret); // Ensure the ciphertext is a PrivateKeyCiphertext instance - expect(ciphertext).toBeInstanceOf(PrivateKeyCiphertext); + expect(ciphertext).instanceof(PrivateKeyCiphertext); // Ensure the decrypted private key is a PrivateKey instance - expect(privateKeyFromCiphertext).toBeInstanceOf(PrivateKey); + expect(privateKeyFromCiphertext).instanceof(PrivateKey); }); it('encrypts and decrypts to and from ciphertext', () => { @@ -130,12 +131,12 @@ describe('WASM Objects', () => { const ciphertext = privateKey.toCiphertext(secret); // Ensure the ciphertext is a PrivateKeyCiphertext instance - expect(ciphertext).toBeInstanceOf(PrivateKeyCiphertext); + expect(ciphertext).instanceof(PrivateKeyCiphertext); const privateKeyFromCiphertext = PrivateKey.fromPrivateKeyCiphertext(ciphertext, secret); // Ensure the decrypted private key is a PrivateKey instance - expect(privateKeyFromCiphertext).toBeInstanceOf(PrivateKey); + expect(privateKeyFromCiphertext).instanceof(PrivateKey); // Ensure the decrypted private key is the same as the original - expect(privateKeyFromCiphertext.to_string()).toBe(privateKey.to_string()); + expect(privateKeyFromCiphertext.to_string()).equal(privateKey.to_string()); }); it('properly assesses equality and inequality', () => { @@ -144,10 +145,10 @@ describe('WASM Objects', () => { const privateKey3 = PrivateKey.from_string(privateKeyString); // Ensure the different private keys are not equal - expect((privateKey1 === privateKey2)).toBeFalsy(); + expect(privateKey1).not.equal(privateKey2); // Ensure the same private keys are equal - expect((privateKey2 === privateKey2)).toBeTruthy(); - expect(privateKey2.to_string()).toBe(privateKey3.to_string()); + expect(privateKey2).equal(privateKey2); + expect(privateKey2.to_string()).equal(privateKey3.to_string()); }); it('has different ciphertexts for the same password, but decrypts to the same key', () => { @@ -159,14 +160,14 @@ describe('WASM Objects', () => { const decryptedPrivateKey2 = PrivateKey.fromPrivateKeyCiphertext(ciphertext2, secret); // Ensure the ciphertexts are different - expect(ciphertext).not.toBe(ciphertext2); + expect(ciphertext).not.equal(ciphertext2); // Ensure the decrypted private keys are both PrivateKey instances - expect(decryptedPrivateKey).toBeInstanceOf(PrivateKey); - expect(decryptedPrivateKey2).toBeInstanceOf(PrivateKey); + expect(decryptedPrivateKey).instanceof(PrivateKey); + expect(decryptedPrivateKey2).instanceof(PrivateKey); // Ensure the decrypted private keys are the same as the original - expect(decryptedPrivateKey.to_string()).toBe(privateKeyString); - expect(decryptedPrivateKey2.to_string()).toBe(privateKeyString); - expect(decryptedPrivateKey.to_string()).toBe(decryptedPrivateKey2.to_string()); + expect(decryptedPrivateKey.to_string()).equal(privateKeyString); + expect(decryptedPrivateKey2.to_string()).equal(privateKeyString); + expect(decryptedPrivateKey.to_string()).equal(decryptedPrivateKey2.to_string()); }); }); @@ -175,18 +176,18 @@ describe('WASM Objects', () => { it('constructs properly from a string', () => { // Ensure the view key is a ViewKey instance - expect(viewKey).toBeInstanceOf(ViewKey); + expect(viewKey).instanceof(ViewKey); // Ensure the view key is the correct value - expect(viewKey.to_string()).toMatch(viewKeyString); + expect(viewKey.to_string()).string(viewKeyString); }); it('derives the correct address', () => { const address = viewKey.to_address(); // Ensure the address is an Address instance - expect(address).toBeInstanceOf(Address); + expect(address).instanceof(Address); // Ensure the address is the correct value - expect(address.to_string()).toMatch(addressString); + expect(address.to_string()).string(addressString); }); it('properly assesses equality and inequality', () => { @@ -195,17 +196,17 @@ describe('WASM Objects', () => { const viewKey3 = ViewKey.from_string(viewKeyString); // Ensure the different view keys are not equal - expect((viewKey1 === viewKey2)).toBeFalsy(); + expect(viewKey1).not.equal(viewKey2); // Ensure the same view keys are equal - expect((viewKey2 === viewKey2)).toBeTruthy(); - expect(viewKey2.to_string()).toBe(viewKey3.to_string()); + expect(viewKey2).equal(viewKey2); + expect(viewKey2.to_string()).equal(viewKey3.to_string()); }); it('can decrypt a record generated by the account', () => { const decryptedRecord = viewKey.decrypt(recordCiphertextString); // Ensure it decrypts to the correct data - expect(decryptedRecord).toBe(recordPlaintextString); + expect(decryptedRecord).equal(recordPlaintextString); }); }); @@ -218,9 +219,9 @@ describe('WASM Objects', () => { const result = signature.verify(address, message); // Ensure the result is a boolean - expect(typeof result).toBe('boolean'); + expect(typeof result).equal('boolean'); // Ensure the signature verified - expect(result).toBe(true); + expect(result).equal(true); }); it('cannot verify a message signed by the wrong private key', () => { @@ -230,9 +231,9 @@ describe('WASM Objects', () => { const result = signature.verify(address, message); // Ensure the result is a boolean - expect(typeof result).toBe('boolean'); + expect(typeof result).equal('boolean'); // Ensure the signature failed to verify - expect(result).toBe(false); + expect(result).equal(false); }); it('can go to and from string', () => { @@ -241,12 +242,12 @@ describe('WASM Objects', () => { const signatureFromString = Signature.from_string(signatureString); // Ensure the signature is a Signature instance - expect(signature).toBeInstanceOf(Signature); + expect(signature).instanceof(Signature); // Ensure from_string returns a Signature instance - expect(signatureFromString).toBeInstanceOf(Signature); + expect(signatureFromString).instanceof(Signature); // Ensure the signature to_string matches the expected values - expect(signature.to_string()).toBe(signatureString); - expect(signatureFromString.to_string()).toBe(signatureString); + expect(signature.to_string()).equal(signatureString); + expect(signatureFromString.to_string()).equal(signatureString); }); }); @@ -259,8 +260,8 @@ describe('WASM Objects', () => { const decryptedKey = ciphertext.decryptToPrivateKey(secret); // Ensure the decrypted key is a PrivateKey instance and is the same as the original - expect(decryptedKey).toBeInstanceOf(PrivateKey); - expect(decryptedKey.to_string()).toBe(privateKeyString); + expect(decryptedKey).instanceof(PrivateKey); + expect(decryptedKey.to_string()).equal(privateKeyString); }); it('should fail to decrypt with a bad secret', () => { @@ -269,10 +270,10 @@ describe('WASM Objects', () => { try { ciphertext.decryptToPrivateKey(badSecret); // Should not get here - expect(true).toBe(false); + expect(true).equal(false); } catch (e) { // Should error out - expect(true).toBe(true); + expect(true).equal(true); } }); @@ -282,12 +283,12 @@ describe('WASM Objects', () => { const decryptedKey2 = ciphertext2.decryptToPrivateKey(secret); // Ensure the ciphertexts are different - expect(ciphertext).not.toBe(ciphertext2); + expect(ciphertext).not.equal(ciphertext2); // Ensure the decrypted are both private key instances and have the same key - expect(decryptedKey).toBeInstanceOf(PrivateKey); - expect(decryptedKey2).toBeInstanceOf(PrivateKey); - expect(decryptedKey.to_string()).toBe(privateKeyString); - expect(decryptedKey2.to_string()).toBe(privateKeyString); + expect(decryptedKey).instanceof(PrivateKey); + expect(decryptedKey2).instanceof(PrivateKey); + expect(decryptedKey.to_string()).equal(privateKeyString); + expect(decryptedKey2.to_string()).equal(privateKeyString); }); it('round trip to and from string for PrivateKeyCiphertext', () => { @@ -297,7 +298,7 @@ describe('WASM Objects', () => { const privateKeyCipherText2 = PrivateKeyCiphertext.fromString(privateKeyCiphertext.toString()); // Assert the round trip to and from string journey results in the same key - expect(privateKeyCiphertext.toString()).toEqual(privateKeyCipherText2.toString()); + expect(privateKeyCiphertext.toString()).equal(privateKeyCipherText2.toString()); }); it('decryption of PrivateKeyCiphertext with edge cases', () => { @@ -309,15 +310,15 @@ describe('WASM Objects', () => { const decryptedPrivateKey = privateKeyCiphertext.decryptToPrivateKey("mypassword"); // Assert that the private key is the same as the original for a valid ciphertext and secret - expect(privateKey.to_string()).toEqual(decryptedPrivateKey.to_string()); + expect(privateKey.to_string()).equal(decryptedPrivateKey.to_string()); // Assert the incorrect secret fails expect(() => { privateKeyCiphertext.decryptToPrivateKey("badpassword"); - }).toThrow(); + }).throw(); // Ensure invalid ciphertexts fail expect(() => { PrivateKeyCiphertext.fromString(bad_ciphertext); - }).toThrow(); + }).throw(); }); }); @@ -329,7 +330,7 @@ describe('WASM Objects', () => { const ciphertext = RecordCiphertext.fromString(recordCiphertextString); // Ensure the string matches the string the record was created from - expect(ciphertext.toString()).toEqual(recordCiphertextString); + expect(ciphertext.toString()).equal(recordCiphertextString); }); it('can be decrypted and identified as owner with a valid view key', () => { @@ -337,18 +338,18 @@ describe('WASM Objects', () => { const isOwner = ciphertext.isOwner(viewKey); // Ensure the record ciphertext is decrypted correctly - expect(plaintext.toString()).toEqual(recordPlaintextString); + expect(plaintext.toString()).equal(recordPlaintextString); // Ensure the view key is identified as the owner of the record - expect(isOwner).toBe(true); + expect(isOwner).equal(true); }); it('cant be decrypted nor identified as owner with a foreign view key', () => { const foreignViewKey = ViewKey.from_string(foreignViewKeyString); // Ensure the record ciphertext cannot be decrypted with a foreign view key - expect(ciphertext.isOwner(foreignViewKey)).toBe(false); + expect(ciphertext.isOwner(foreignViewKey)).equal(false); // Ensure the record ciphertext cannot be decrypted with a foreign view key - expect(() => ciphertext.decrypt(foreignViewKey)).toThrow(); + expect(() => ciphertext.decrypt(foreignViewKey)).throw(); }); }); @@ -357,9 +358,9 @@ describe('WASM Objects', () => { const plaintext = RecordPlaintext.fromString(recordPlaintextString); // Ensure the string matches the string the record was created from - expect(plaintext.toString()).toEqual(recordPlaintextString); + expect(plaintext.toString()).equal(recordPlaintextString); // Ensure the record has the correct number of microcredits - expect(plaintext.microcredits()).toEqual(BigInt(1500000000000000)); + expect(plaintext.microcredits()).equal(BigInt(1500000000000000)); }); }); diff --git a/sdk/tsconfig.json b/sdk/tsconfig.json index de3592536..b933e4d3d 100644 --- a/sdk/tsconfig.json +++ b/sdk/tsconfig.json @@ -17,7 +17,7 @@ // stricter type-checking for stronger correctness. Recommended by TS "strict": true, // use Node's module resolution algorithm, instead of the legacy TS one - "moduleResolution": "node", + "moduleResolution": "bundler", // interop between ESM and CJS modules. Recommended by TS "esModuleInterop": true, // significant perf increase by skipping checking .d.ts files, particularly those in node_modules. Recommended by TS diff --git a/wasm/Cargo.lock b/wasm/Cargo.lock index 0f7eb508b..6b3360edb 100644 --- a/wasm/Cargo.lock +++ b/wasm/Cargo.lock @@ -1539,7 +1539,7 @@ dependencies = [ [[package]] name = "snarkvm-algorithms" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "aleo-std", "anyhow", @@ -1570,7 +1570,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "snarkvm-circuit-account", "snarkvm-circuit-algorithms", @@ -1584,7 +1584,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-account" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "snarkvm-circuit-algorithms", "snarkvm-circuit-network", @@ -1595,7 +1595,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-algorithms" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "snarkvm-circuit-types", "snarkvm-console-algorithms", @@ -1605,7 +1605,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-collections" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "snarkvm-circuit-algorithms", "snarkvm-circuit-types", @@ -1615,7 +1615,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-environment" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "indexmap", "itertools", @@ -1633,12 +1633,12 @@ dependencies = [ [[package]] name = "snarkvm-circuit-environment-witness" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" [[package]] name = "snarkvm-circuit-network" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "snarkvm-circuit-algorithms", "snarkvm-circuit-collections", @@ -1649,7 +1649,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-program" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "paste", "snarkvm-circuit-account", @@ -1664,7 +1664,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "snarkvm-circuit-environment", "snarkvm-circuit-types-address", @@ -1679,7 +1679,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types-address" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "snarkvm-circuit-environment", "snarkvm-circuit-types-boolean", @@ -1692,7 +1692,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types-boolean" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "snarkvm-circuit-environment", "snarkvm-console-types-boolean", @@ -1701,7 +1701,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types-field" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "snarkvm-circuit-environment", "snarkvm-circuit-types-boolean", @@ -1711,7 +1711,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types-group" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "snarkvm-circuit-environment", "snarkvm-circuit-types-boolean", @@ -1723,7 +1723,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types-integers" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "snarkvm-circuit-environment", "snarkvm-circuit-types-boolean", @@ -1735,7 +1735,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types-scalar" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "snarkvm-circuit-environment", "snarkvm-circuit-types-boolean", @@ -1746,7 +1746,7 @@ dependencies = [ [[package]] name = "snarkvm-circuit-types-string" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "snarkvm-circuit-environment", "snarkvm-circuit-types-boolean", @@ -1758,7 +1758,7 @@ dependencies = [ [[package]] name = "snarkvm-console" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "snarkvm-console-account", "snarkvm-console-algorithms", @@ -1771,7 +1771,7 @@ dependencies = [ [[package]] name = "snarkvm-console-account" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "bs58", "snarkvm-console-network", @@ -1782,7 +1782,7 @@ dependencies = [ [[package]] name = "snarkvm-console-algorithms" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "blake2s_simd", "smallvec", @@ -1795,7 +1795,7 @@ dependencies = [ [[package]] name = "snarkvm-console-collections" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "aleo-std", "rayon", @@ -1806,7 +1806,7 @@ dependencies = [ [[package]] name = "snarkvm-console-network" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "anyhow", "indexmap", @@ -1829,7 +1829,7 @@ dependencies = [ [[package]] name = "snarkvm-console-network-environment" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "anyhow", "bech32", @@ -1847,7 +1847,7 @@ dependencies = [ [[package]] name = "snarkvm-console-program" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "enum-iterator", "enum_index", @@ -1869,7 +1869,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "snarkvm-console-network-environment", "snarkvm-console-types-address", @@ -1884,7 +1884,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types-address" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "snarkvm-console-network-environment", "snarkvm-console-types-boolean", @@ -1895,7 +1895,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types-boolean" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "snarkvm-console-network-environment", ] @@ -1903,7 +1903,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types-field" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "snarkvm-console-network-environment", "snarkvm-console-types-boolean", @@ -1913,7 +1913,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types-group" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "snarkvm-console-network-environment", "snarkvm-console-types-boolean", @@ -1924,7 +1924,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types-integers" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "snarkvm-console-network-environment", "snarkvm-console-types-boolean", @@ -1935,7 +1935,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types-scalar" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "snarkvm-console-network-environment", "snarkvm-console-types-boolean", @@ -1946,7 +1946,7 @@ dependencies = [ [[package]] name = "snarkvm-console-types-string" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "snarkvm-console-network-environment", "snarkvm-console-types-boolean", @@ -1957,7 +1957,7 @@ dependencies = [ [[package]] name = "snarkvm-curves" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "rand", "rayon", @@ -1971,7 +1971,7 @@ dependencies = [ [[package]] name = "snarkvm-fields" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "aleo-std", "anyhow", @@ -1988,7 +1988,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-authority" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "anyhow", "rand", @@ -2000,7 +2000,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-block" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "indexmap", "rayon", @@ -2020,7 +2020,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-committee" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "indexmap", "rayon", @@ -2032,7 +2032,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-narwhal-batch-certificate" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "indexmap", "rayon", @@ -2045,7 +2045,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-narwhal-batch-header" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "indexmap", "rayon", @@ -2057,7 +2057,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-narwhal-data" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "bytes", "serde_json", @@ -2067,7 +2067,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-narwhal-subdag" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "indexmap", "rayon", @@ -2082,7 +2082,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-narwhal-transmission-id" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "snarkvm-console", "snarkvm-ledger-puzzle", @@ -2091,7 +2091,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-puzzle" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "aleo-std", "anyhow", @@ -2111,7 +2111,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-puzzle-epoch" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "aleo-std", "anyhow", @@ -2132,7 +2132,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-query" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "async-trait", "reqwest", @@ -2145,7 +2145,7 @@ dependencies = [ [[package]] name = "snarkvm-ledger-store" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "aleo-std-storage", "anyhow", @@ -2168,7 +2168,7 @@ dependencies = [ [[package]] name = "snarkvm-parameters" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "aleo-std", "anyhow", @@ -2196,7 +2196,7 @@ dependencies = [ [[package]] name = "snarkvm-synthesizer" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "aleo-std", "anyhow", @@ -2227,7 +2227,7 @@ dependencies = [ [[package]] name = "snarkvm-synthesizer-process" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "aleo-std", "colored", @@ -2235,6 +2235,7 @@ dependencies = [ "once_cell", "parking_lot", "rand", + "rand_chacha", "rayon", "serde_json", "snarkvm-circuit", @@ -2250,7 +2251,7 @@ dependencies = [ [[package]] name = "snarkvm-synthesizer-program" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "indexmap", "paste", @@ -2264,7 +2265,7 @@ dependencies = [ [[package]] name = "snarkvm-synthesizer-snark" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "bincode", "once_cell", @@ -2277,7 +2278,7 @@ dependencies = [ [[package]] name = "snarkvm-utilities" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "aleo-std", "anyhow", @@ -2298,7 +2299,7 @@ dependencies = [ [[package]] name = "snarkvm-utilities-derives" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "proc-macro2", "quote 1.0.36", @@ -2308,7 +2309,7 @@ dependencies = [ [[package]] name = "snarkvm-wasm" version = "0.16.19" -source = "git+https://github.com/AleoNet/snarkVM.git?rev=be171ce0720544c2bc51e27e1674a62fff585adc#be171ce0720544c2bc51e27e1674a62fff585adc" +source = "git+https://github.com/AleoNet/snarkVM.git?rev=3d42aa04a058cd5f46a1880b421313e1c04a63dc#3d42aa04a058cd5f46a1880b421313e1c04a63dc" dependencies = [ "getrandom", "snarkvm-circuit-network", diff --git a/wasm/Cargo.toml b/wasm/Cargo.toml index e91406bc5..fb6313b71 100644 --- a/wasm/Cargo.toml +++ b/wasm/Cargo.toml @@ -3,7 +3,7 @@ name = "aleo-wasm" version = "0.6.9" authors = [ "The Provable Team" ] description = "WebAssembly based toolkit for developing zero-knowledge applications with Aleo" -homepage = "https://aleo.org" +homepage = "https://provable.com" repository = "https://github.com/ProvableHQ/sdk" keywords = [ "aleo", @@ -24,47 +24,47 @@ doctest = false [dependencies.snarkvm-circuit-network] version = "0.16.19" git = "https://github.com/AleoNet/snarkVM.git" -rev = "be171ce0720544c2bc51e27e1674a62fff585adc" +rev = "3d42aa04a058cd5f46a1880b421313e1c04a63dc" [dependencies.snarkvm-console] version = "0.16.19" git = "https://github.com/AleoNet/snarkVM.git" -rev = "be171ce0720544c2bc51e27e1674a62fff585adc" +rev = "3d42aa04a058cd5f46a1880b421313e1c04a63dc" features = [ "wasm" ] [dependencies.snarkvm-ledger-block] version = "0.16.19" git = "https://github.com/AleoNet/snarkVM.git" -rev = "be171ce0720544c2bc51e27e1674a62fff585adc" +rev = "3d42aa04a058cd5f46a1880b421313e1c04a63dc" features = [ "wasm" ] [dependencies.snarkvm-ledger-query] version = "0.16.19" git = "https://github.com/AleoNet/snarkVM.git" -rev = "be171ce0720544c2bc51e27e1674a62fff585adc" +rev = "3d42aa04a058cd5f46a1880b421313e1c04a63dc" features = [ "async", "wasm" ] [dependencies.snarkvm-ledger-store] version = "0.16.19" git = "https://github.com/AleoNet/snarkVM.git" -rev = "be171ce0720544c2bc51e27e1674a62fff585adc" +rev = "3d42aa04a058cd5f46a1880b421313e1c04a63dc" [dependencies.snarkvm-parameters] version = "0.16.19" git = "https://github.com/AleoNet/snarkVM.git" -rev = "be171ce0720544c2bc51e27e1674a62fff585adc" +rev = "3d42aa04a058cd5f46a1880b421313e1c04a63dc" features = [ "wasm" ] [dependencies.snarkvm-synthesizer] version = "0.16.19" git = "https://github.com/AleoNet/snarkVM.git" -rev = "be171ce0720544c2bc51e27e1674a62fff585adc" +rev = "3d42aa04a058cd5f46a1880b421313e1c04a63dc" features = [ "async", "wasm" ] [dependencies.snarkvm-wasm] version = "0.16.19" git = "https://github.com/AleoNet/snarkVM.git" -rev = "be171ce0720544c2bc51e27e1674a62fff585adc" +rev = "3d42aa04a058cd5f46a1880b421313e1c04a63dc" features = [ "console", "fields", "utilities" ] [dependencies.anyhow] @@ -148,6 +148,8 @@ features = [ default = [ "serial", "browser" ] serial = [ "snarkvm-console/serial", "snarkvm-synthesizer/serial", "snarkvm-ledger-query/serial", "snarkvm-ledger-block/serial", "snarkvm-ledger-store/serial" ] browser = [ ] +testnet = [ ] +mainnet = [ ] ## Profiles [profile.release] diff --git a/wasm/README.md b/wasm/README.md index 5d1592bb1..d05a7869e 100644 --- a/wasm/README.md +++ b/wasm/README.md @@ -1,5 +1,5 @@ [![Crates.io](https://img.shields.io/crates/v/aleo-wasm.svg?color=neon)](https://crates.io/crates/aleo-wasm) -[![Authors](https://img.shields.io/badge/authors-Aleo-orange.svg)](https://aleo.org) +[![Authors](https://img.shields.io/badge/authors-Aleo-orange.svg)](https://provable.com) [![License](https://img.shields.io/badge/License-GPLv3-blue.svg)](./LICENSE.md) [![github]](https://github.com/ProvableHQ/sdk) [![crates-io]](https://crates.io/crates/aleo-wasm) [![docs-rs]](https://docs.rs/aleo-wasm/latest/aleo-wasm/) @@ -12,9 +12,9 @@ Aleo JavaScript and WebAssembly bindings for building zero-knowledge web applications. -`Rust` compiles easily to `WebAssembly`, but creating the glue code necessary to use compiled WebAssembly binaries -from other languages such as JavaScript is a challenging task. `wasm-bindgen` is a tool that simplifies this process by -auto-generating JavaScript bindings to Rust code that has been compiled into WebAssembly. +`Rust` compiles easily to `WebAssembly`, but creating the glue code necessary to use compiled WebAssembly binaries +from other languages such as JavaScript is a challenging task. `wasm-bindgen` is a tool that simplifies this process by +auto-generating JavaScript bindings to Rust code that has been compiled into WebAssembly. This crate uses `wasm-bindgen` to create JavaScript bindings to Aleo source code so that it can be used to create zero-knowledge proofs directly within web browsers and `Node.js`. @@ -56,7 +56,7 @@ wasm-pack test --[firefox/chrome/safari] ## Building Web Apps -Further documentation and tutorials as to how to use the modules built from this crate to build web apps will be built +Further documentation and tutorials as to how to use the modules built from this crate to build web apps will be built in the future. However, in the meantime, the [provable.tools](https://provable.tools) website is a good -example of how to use these modules to build a web app. Its source code can be found in the +example of how to use these modules to build a web app. Its source code can be found in the [Aleo SDK](https://github.com/ProvableHQ/sdk) repo in the `website` folder. diff --git a/wasm/build.js b/wasm/build.js new file mode 100644 index 000000000..78dc78441 --- /dev/null +++ b/wasm/build.js @@ -0,0 +1,256 @@ +import * as $fs from "node:fs/promises"; +import { rollup } from "rollup"; +import virtual from "@rollup/plugin-virtual"; +import rust from "@wasm-tool/rollup-plugin-rust"; + + +async function buildRollup(input, output) { + const bundle = await rollup(input); + + try { + await bundle.write(output); + + } finally { + await bundle.close(); + } +} + + +async function buildWasm(network) { + await buildRollup({ + input: { + "aleo_wasm": "entry", + }, + plugins: [ + virtual({ + "entry": `export { default } from "./Cargo.toml";`, + }), + + 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,${network}`, + "-Z", "build-std=panic_abort,std", + ], + + experimental: { + typescriptDeclarationDir: `dist/${network}`, + }, + }), + ], + }, { + dir: `dist/${network}`, + format: "es", + sourcemap: true, + assetFileNames: `[name][extname]`, + }); +} + + +async function buildJS(network) { + const js = `import wasm from "./dist/${network}/aleo_wasm.js"; + +const { + initThreadPool: wasmInitThreadPool, + Address, + Execution, + ExecutionResponse, + Field, + Metadata, + OfflineQuery, + Private, + PrivateKey, + PrivateKeyCiphertext, + Program, + ProvingKey, + RecordCiphertext, + RecordPlaintext, + ProgramManager, + Signature, + Transaction, + ViewKey, + VerifyingKey, + verifyFunctionExecution, +} = await wasm({ + importHook: () => { + return new URL("aleo_wasm.wasm", import.meta.url); + }, +}); + +async function initThreadPool(threads) { + if (threads == null) { + threads = navigator.hardwareConcurrency; + } + + console.info(\`Spawning \${threads} threads\`); + + await wasmInitThreadPool(new URL("worker.js", import.meta.url), threads); +} + +export { + initThreadPool, + Address, + Execution, + ExecutionResponse, + Field, + Metadata, + OfflineQuery, + PrivateKey, + PrivateKeyCiphertext, + Program, + ProvingKey, + RecordCiphertext, + RecordPlaintext, + ProgramManager, + Signature, + Transaction, + ViewKey, + VerifyingKey, + verifyFunctionExecution, +};`; + + await buildRollup({ + input: { + "index": "entry", + }, + plugins: [ + virtual({ + "entry": js, + }), + ], + }, { + dir: `dist/${network}`, + format: "es", + sourcemap: true, + }); +} + + +async function buildWorker(network) { + const worker = `import wasm from "./dist/${network}/aleo_wasm.js"; + +async function initializeWorker(wasm) { + // Wait for the main thread to send us the Module, Memory, and Rayon thread pointer. + 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(), + ]); + + // Runs the Wasm inside of the Worker, but using the main thread's Module and Memory. + const exports = await initWasm({ + initializeHook: (init, path) => init(module, memory), + }); + + // Tells the main thread that we're finished initializing. + postMessage(null); + + // This will hang the Worker while running the Rayon thread. + exports.runRayonThread(address); + + // When the Rayon thread is finished, close the Worker. + close(); +} + +await initializeWorker(wasm);`; + + await buildRollup({ + input: { + "worker": "entry", + }, + plugins: [ + virtual({ + "entry": worker, + }), + ], + }, { + dir: `dist/${network}`, + format: "es", + sourcemap: true, + }); +} + + +async function buildTypes(network) { + const js = `/** + * Initializes a thread pool of Workers. This enables multi-threading, which significantly improves performance. + * + * @param {number | undefined} threads Number of threads to spawn. If not specified, uses the number of available cores. + */ +export function initThreadPool(threads?: number): Promise; + +export { + Address, + Execution, + ExecutionResponse, + Field, + Metadata, + OfflineQuery, + PrivateKey, + PrivateKeyCiphertext, + Program, + ProvingKey, + RecordCiphertext, + RecordPlaintext, + ProgramManager, + Signature, + Transaction, + ViewKey, + VerifyingKey, + verifyFunctionExecution, +} from "./aleo_wasm";`; + + const worker = `export {};`; + + await $fs.mkdir(`dist/${network}`, { recursive: true }) + + await Promise.all([ + $fs.writeFile(`dist/${network}/index.d.ts`, js), + $fs.writeFile(`dist/${network}/worker.d.ts`, worker), + ]); +} + + +// This uses multiple Rollup builds, instead of 1 build. +// +// The reason is because the `worker.js` file needs to be +// fully self-contained, it cannot contain imports to other +// chunks. +// +// But Rollup doesn't support standalone entry points, so we +// hack around it by instead using multiple builds. +// +// But we want to share the Wasm build between the `index.js` +// and `worker.js` builds, so we build the Wasm, and then +// build the `index.js` and `worker.js` separately. +async function build(network) { + await Promise.all([ + buildTypes(network), + buildWasm(network), + ]); + + await Promise.all([ + buildJS(network), + buildWorker(network), + ]); +} + + +const networks = [ + "testnet", + "mainnet", +]; + +await Promise.all(networks.map(build)); diff --git a/wasm/js/index.js b/wasm/js/index.js deleted file mode 100644 index dffa98604..000000000 --- a/wasm/js/index.js +++ /dev/null @@ -1,60 +0,0 @@ -import wasm from "../dist/wasm.js"; - -const { - initThreadPool: wasmInitThreadPool, - Address, - Execution, - ExecutionResponse, - Field, - Metadata, - OfflineQuery, - Private, - PrivateKey, - PrivateKeyCiphertext, - Program, - ProvingKey, - RecordCiphertext, - RecordPlaintext, - ProgramManager, - Signature, - Transaction, - ViewKey, - VerifyingKey, - verifyFunctionExecution, -} = await wasm({ - importHook: () => { - return new URL("assets/aleo_wasm.wasm", import.meta.url); - }, -}); - -async function initThreadPool(threads) { - if (threads == null) { - threads = navigator.hardwareConcurrency; - } - - console.info(`Spawning ${threads} threads`); - - await wasmInitThreadPool(new URL("worker.js", import.meta.url), threads); -} - -export { - initThreadPool, - Address, - Execution, - ExecutionResponse, - Field, - Metadata, - OfflineQuery, - PrivateKey, - PrivateKeyCiphertext, - Program, - ProvingKey, - RecordCiphertext, - RecordPlaintext, - ProgramManager, - Signature, - Transaction, - ViewKey, - VerifyingKey, - verifyFunctionExecution, -}; diff --git a/wasm/js/types/index.d.ts b/wasm/js/types/index.d.ts deleted file mode 100644 index 23560012d..000000000 --- a/wasm/js/types/index.d.ts +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Initializes a thread pool of Workers. This enables multi-threading, which significantly improves performance. - * - * @param {number | undefined} threads Number of threads to spawn. If not specified, uses the number of available cores. - */ -export function initThreadPool(threads?: number): Promise; - -export { - Address, - Execution, - ExecutionResponse, - Field, - Metadata, - OfflineQuery, - PrivateKey, - PrivateKeyCiphertext, - Program, - ProvingKey, - RecordCiphertext, - RecordPlaintext, - ProgramManager, - Signature, - Transaction, - ViewKey, - VerifyingKey, - verifyFunctionExecution, -} from "./crates/aleo_wasm"; diff --git a/wasm/js/types/worker.d.ts b/wasm/js/types/worker.d.ts deleted file mode 100644 index 8cec2e9ce..000000000 --- a/wasm/js/types/worker.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; \ No newline at end of file diff --git a/wasm/js/wasm.js b/wasm/js/wasm.js deleted file mode 100644 index aa6e8957d..000000000 --- a/wasm/js/wasm.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from "../Cargo.toml"; diff --git a/wasm/js/worker.js b/wasm/js/worker.js deleted file mode 100644 index 7542fbc23..000000000 --- a/wasm/js/worker.js +++ /dev/null @@ -1,36 +0,0 @@ -import wasm from "../dist/wasm.js"; - -async function initializeWorker(wasm) { - // Wait for the main thread to send us the Module, Memory, and Rayon thread pointer. - 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(), - ]); - - // Runs the Wasm inside of the Worker, but using the main thread's Module and Memory. - const exports = await initWasm({ - initializeHook: (init, path) => init(module, memory), - }); - - // Tells the main thread that we're finished initializing. - postMessage(null); - - // This will hang the Worker while running the Rayon thread. - exports.runRayonThread(address); - - // When the Rayon thread is finished, close the Worker. - close(); -} - -await initializeWorker(wasm); diff --git a/wasm/package.json b/wasm/package.json index 2661e9597..b97c841d6 100644 --- a/wasm/package.json +++ b/wasm/package.json @@ -7,12 +7,16 @@ ], "license": "GPL-3.0", "type": "module", - "main": "./dist/index.js", - "browser": "./dist/index.js", - "types": "./dist/index.d.ts", + "main": "./dist/testnet/index.js", + "browser": "./dist/testnet/index.js", + "types": "./dist/testnet/index.d.ts", "exports": { - ".": "./dist/index.js", - "./worker.js": "./dist/worker.js" + ".": "./dist/testnet/index.js", + "./worker.js": "./dist/testnet/worker.js", + "./testnet.js": "./dist/testnet/index.js", + "./testnet/worker.js": "./dist/testnet/worker.js", + "./mainnet.js": "./dist/mainnet/index.js", + "./mainnet/worker.js": "./dist/mainnet/worker.js" }, "files": [ "dist", @@ -34,13 +38,13 @@ }, "homepage": "https://github.com/ProvableHQ/sdk#readme", "scripts": { - "build": "rimraf dist && rollup -c rollup.config.js && cpr js/types dist && rimraf dist/wasm*", + "build": "rimraf dist && node build.js", "prepublish": "yarn build", "test": "node test.js" }, "devDependencies": { + "@rollup/plugin-virtual": "^3.0.2", "@wasm-tool/rollup-plugin-rust": "^2.4.2", - "cpr": "^3.0.1", "rimraf": "^5.0.1", "rollup": "^3.27.2" } diff --git a/wasm/rollup.config.js b/wasm/rollup.config.js deleted file mode 100644 index b95abff4d..000000000 --- a/wasm/rollup.config.js +++ /dev/null @@ -1,64 +0,0 @@ -import rust from "@wasm-tool/rollup-plugin-rust"; - -// This uses 3 separate builds, instead of 1 build. -// -// The reason is because the `worker.js` file needs to be -// fully self-contained, it cannot contain imports to other -// chunks. -// -// But Rollup doesn't support standalone entry points, so we -// hack around it by instead using multiple builds. -// -// But we want to share the Wasm build between the `index.js` -// and `worker.js` builds, so we build the Wasm, and then -// build the `index.js` and `worker.js` separately. -export default [ - { - input: { - wasm: "./js/wasm.js", - }, - output: { - dir: `dist`, - format: "es", - sourcemap: true, - assetFileNames: "assets/[name][extname]", - }, - 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", - }, - }), - ], - }, - - { - input: { - index: "./js/index.js", - }, - output: { - dir: `dist`, - format: "es", - sourcemap: true, - }, - }, - - { - input: { - worker: "./js/worker.js", - }, - output: { - dir: `dist`, - format: "es", - sourcemap: true, - }, - }, -]; diff --git a/wasm/src/lib.rs b/wasm/src/lib.rs index 7eded620f..986cd2653 100644 --- a/wasm/src/lib.rs +++ b/wasm/src/lib.rs @@ -16,7 +16,7 @@ //! //! [![Crates.io](https://img.shields.io/crates/v/aleo-wasm.svg?color=neon)](https://crates.io/crates/aleo-wasm) -//! [![Authors](https://img.shields.io/badge/authors-Aleo-orange.svg)](https://aleo.org) +//! [![Authors](https://img.shields.io/badge/authors-Aleo-orange.svg)](https://provable.com) //! [![License](https://img.shields.io/badge/License-GPLv3-blue.svg)](./LICENSE.md) //! //! [![github]](https://github.com/ProvableHQ/sdk) [![crates-io]](https://crates.io/crates/aleo-wasm) [![docs-rs]](https://docs.rs/aleo-wasm/latest/aleo-wasm/) diff --git a/wasm/src/programs/execution.rs b/wasm/src/programs/execution.rs index c189f7e70..9548297a2 100644 --- a/wasm/src/programs/execution.rs +++ b/wasm/src/programs/execution.rs @@ -106,7 +106,7 @@ mod tests { #[wasm_bindgen_test] fn test_execution_verification() { let execution = Execution::from_string(EXECUTION).unwrap(); - let verifying_key_bytes = snarkvm_parameters::testnet::TransferPublicVerifier::load_bytes().unwrap(); + let verifying_key_bytes = crate::types::native::parameters::TransferPublicVerifier::load_bytes().unwrap(); let verifying_key = VerifyingKey::from_bytes(&verifying_key_bytes).unwrap(); assert!( verify_function_execution(&execution, &verifying_key, &Program::get_credits_program(), "transfer_public") diff --git a/wasm/src/programs/manager/mod.rs b/wasm/src/programs/manager/mod.rs index c659b212f..7fcd6457c 100644 --- a/wasm/src/programs/manager/mod.rs +++ b/wasm/src/programs/manager/mod.rs @@ -20,7 +20,7 @@ pub mod join; pub mod split; pub mod transfer; -const DEFAULT_URL: &str = "https://api.explorer.aleo.org/v1"; +const DEFAULT_URL: &str = "https://api.explorer.provable.com/v1"; use crate::{KeyPair, PrivateKey, ProvingKey, RecordPlaintext, VerifyingKey}; diff --git a/wasm/src/programs/proving_key/credits.rs b/wasm/src/programs/proving_key/credits.rs index 45ff7b573..f6c3057e5 100644 --- a/wasm/src/programs/proving_key/credits.rs +++ b/wasm/src/programs/proving_key/credits.rs @@ -33,7 +33,7 @@ impl ProvingKey { /// @returns {boolean} returns true if the proving key is for the bond_public function, false if otherwise #[wasm_bindgen(js_name = "isBondPublicProver")] pub fn is_bond_public_prover(&self) -> bool { - self.checksum() == ProvingKey::prover_checksum(snarkvm_parameters::testnet::BondPublicProver::METADATA) + self.checksum() == ProvingKey::prover_checksum(crate::types::native::parameters::BondPublicProver::METADATA) } /// Verify if the proving key is for the bond_validator function @@ -45,7 +45,7 @@ impl ProvingKey { /// @returns {boolean} returns true if the proving key is for the bond_validator function, false if otherwise #[wasm_bindgen(js_name = "isBondValidatorProver")] pub fn is_bond_validator_prover(&self) -> bool { - self.checksum() == ProvingKey::prover_checksum(snarkvm_parameters::testnet::BondValidatorProver::METADATA) + self.checksum() == ProvingKey::prover_checksum(crate::types::native::parameters::BondValidatorProver::METADATA) } /// Verify if the proving key is for the claim_unbond function @@ -57,7 +57,8 @@ impl ProvingKey { /// @returns {boolean} returns true if the proving key is for the claim_unbond function, false if otherwise #[wasm_bindgen(js_name = "isClaimUnbondPublicProver")] pub fn is_claim_unbond_public_prover(&self) -> bool { - self.checksum() == ProvingKey::prover_checksum(snarkvm_parameters::testnet::ClaimUnbondPublicProver::METADATA) + self.checksum() + == ProvingKey::prover_checksum(crate::types::native::parameters::ClaimUnbondPublicProver::METADATA) } /// Verify if the proving key is for the fee_private function @@ -69,7 +70,7 @@ impl ProvingKey { /// @returns {boolean} returns true if the proving key is for the fee_private function, false if otherwise #[wasm_bindgen(js_name = "isFeePrivateProver")] pub fn is_fee_private_prover(&self) -> bool { - self.checksum() == ProvingKey::prover_checksum(snarkvm_parameters::testnet::FeePrivateProver::METADATA) + self.checksum() == ProvingKey::prover_checksum(crate::types::native::parameters::FeePrivateProver::METADATA) } /// Verify if the proving key is for the fee_public function @@ -81,7 +82,7 @@ impl ProvingKey { /// @returns {boolean} returns true if the proving key is for the fee_public function, false if otherwise #[wasm_bindgen(js_name = "isFeePublicProver")] pub fn is_fee_public_prover(&self) -> bool { - self.checksum() == ProvingKey::prover_checksum(snarkvm_parameters::testnet::FeePublicProver::METADATA) + self.checksum() == ProvingKey::prover_checksum(crate::types::native::parameters::FeePublicProver::METADATA) } /// Verify if the proving key is for the inclusion function @@ -93,7 +94,7 @@ impl ProvingKey { /// @returns {boolean} returns true if the proving key is for the inclusion function, false if otherwise #[wasm_bindgen(js_name = "isInclusionProver")] pub fn is_inclusion_prover(&self) -> bool { - self.checksum() == ProvingKey::prover_checksum(snarkvm_parameters::testnet::InclusionProver::METADATA) + self.checksum() == ProvingKey::prover_checksum(crate::types::native::parameters::InclusionProver::METADATA) } /// Verify if the proving key is for the join function @@ -105,7 +106,7 @@ impl ProvingKey { /// @returns {boolean} returns true if the proving key is for the join function, false if otherwise #[wasm_bindgen(js_name = "isJoinProver")] pub fn is_join_prover(&self) -> bool { - self.checksum() == ProvingKey::prover_checksum(snarkvm_parameters::testnet::JoinProver::METADATA) + self.checksum() == ProvingKey::prover_checksum(crate::types::native::parameters::JoinProver::METADATA) } /// Verify if the proving key is for the set_validator_state function @@ -117,7 +118,8 @@ impl ProvingKey { /// @returns {boolean} returns true if the proving key is for the set_validator_state function, false if otherwise #[wasm_bindgen(js_name = "isSetValidatorStateProver")] pub fn is_set_validator_state_prover(&self) -> bool { - self.checksum() == ProvingKey::prover_checksum(snarkvm_parameters::testnet::SetValidatorStateProver::METADATA) + self.checksum() + == ProvingKey::prover_checksum(crate::types::native::parameters::SetValidatorStateProver::METADATA) } /// Verify if the proving key is for the split function @@ -129,7 +131,7 @@ impl ProvingKey { /// @returns {boolean} returns true if the proving key is for the split function, false if otherwise #[wasm_bindgen(js_name = "isSplitProver")] pub fn is_split_prover(&self) -> bool { - self.checksum() == ProvingKey::prover_checksum(snarkvm_parameters::testnet::SplitProver::METADATA) + self.checksum() == ProvingKey::prover_checksum(crate::types::native::parameters::SplitProver::METADATA) } /// Verify if the proving key is for the transfer_private function @@ -141,7 +143,8 @@ impl ProvingKey { /// @returns {boolean} returns true if the proving key is for the transfer_private function, false if otherwise #[wasm_bindgen(js_name = "isTransferPrivateProver")] pub fn is_transfer_private_prover(&self) -> bool { - self.checksum() == ProvingKey::prover_checksum(snarkvm_parameters::testnet::TransferPrivateProver::METADATA) + self.checksum() + == ProvingKey::prover_checksum(crate::types::native::parameters::TransferPrivateProver::METADATA) } /// Verify if the proving key is for the transfer_private_to_public function @@ -154,7 +157,7 @@ impl ProvingKey { #[wasm_bindgen(js_name = "isTransferPrivateToPublicProver")] pub fn is_transfer_private_to_public_prover(&self) -> bool { self.checksum() - == ProvingKey::prover_checksum(snarkvm_parameters::testnet::TransferPrivateToPublicProver::METADATA) + == ProvingKey::prover_checksum(crate::types::native::parameters::TransferPrivateToPublicProver::METADATA) } /// Verify if the proving key is for the transfer_public function @@ -166,7 +169,7 @@ impl ProvingKey { /// @returns {boolean} returns true if the proving key is for the transfer_public function, false if otherwise #[wasm_bindgen(js_name = "isTransferPublicProver")] pub fn is_transfer_public_prover(&self) -> bool { - self.checksum() == ProvingKey::prover_checksum(snarkvm_parameters::testnet::TransferPublicProver::METADATA) + self.checksum() == ProvingKey::prover_checksum(crate::types::native::parameters::TransferPublicProver::METADATA) } /// Verify if the proving key is for the transfer_public_as_signer function @@ -179,7 +182,7 @@ impl ProvingKey { #[wasm_bindgen(js_name = "isTransferPublicAsSignerProver")] pub fn is_transfer_public_as_signer_prover(&self) -> bool { self.checksum() - == ProvingKey::prover_checksum(snarkvm_parameters::testnet::TransferPublicAsSignerProver::METADATA) + == ProvingKey::prover_checksum(crate::types::native::parameters::TransferPublicAsSignerProver::METADATA) } /// Verify if the proving key is for the transfer_public_to_private function @@ -192,7 +195,7 @@ impl ProvingKey { #[wasm_bindgen(js_name = "isTransferPublicToPrivateProver")] pub fn is_transfer_public_to_private_prover(&self) -> bool { self.checksum() - == ProvingKey::prover_checksum(snarkvm_parameters::testnet::TransferPublicToPrivateProver::METADATA) + == ProvingKey::prover_checksum(crate::types::native::parameters::TransferPublicToPrivateProver::METADATA) } /// Verify if the proving key is for the unbond_public function @@ -204,7 +207,7 @@ impl ProvingKey { /// @returns {boolean} returns true if the proving key is for the unbond_public_prover function, false if otherwise #[wasm_bindgen(js_name = "isUnbondPublicProver")] pub fn is_unbond_public_prover(&self) -> bool { - self.checksum() == ProvingKey::prover_checksum(snarkvm_parameters::testnet::UnbondPublicProver::METADATA) + self.checksum() == ProvingKey::prover_checksum(crate::types::native::parameters::UnbondPublicProver::METADATA) } } diff --git a/wasm/src/programs/proving_key/mod.rs b/wasm/src/programs/proving_key/mod.rs index 452e835f6..d9c01c127 100644 --- a/wasm/src/programs/proving_key/mod.rs +++ b/wasm/src/programs/proving_key/mod.rs @@ -127,10 +127,13 @@ mod tests { ProvingKey::from_string(&transfer_public_proving_key_string).unwrap(); assert_eq!(key, transfer_public_proving_key_from_string); + #[cfg(feature = "testnet")] + let checksum = "846f86cabf9fa50e5abe347e559a8e9f3018459b5af9fdf52f1c44892b05f7e5"; + + #[cfg(feature = "mainnet")] + let checksum = "f8e5f6437b945174b62313ece8a1c9dcbeac5dfff5b0fef2e968c9b92f86da06"; + let transfer_public_proving_key_checksum = key.checksum(); - assert_eq!( - transfer_public_proving_key_checksum, - "846f86cabf9fa50e5abe347e559a8e9f3018459b5af9fdf52f1c44892b05f7e5" - ); + assert_eq!(transfer_public_proving_key_checksum, checksum); } } diff --git a/wasm/src/programs/verifying_key/metadata.rs b/wasm/src/programs/verifying_key/metadata.rs index 561b888e0..c09342f56 100644 --- a/wasm/src/programs/verifying_key/metadata.rs +++ b/wasm/src/programs/verifying_key/metadata.rs @@ -36,7 +36,7 @@ pub struct Metadata { } impl Metadata { - const BASE_URL: &'static str = "https://parameters.aleo.org/testnet/"; + const BASE_URL: &'static str = crate::types::native::BASE_URL; fn new(name: &str, verifying_key: &str, locator: &str, prover: &'static str, verifier: &'static str) -> Self { fn url(function_name: &str, kind: &str, proving_key_metadata: &'static str) -> String { @@ -69,8 +69,8 @@ impl Metadata { "bond_public", "bondPublicVerifier", "credits.aleo/bond_public", - snarkvm_parameters::testnet::BondPublicProver::METADATA, - snarkvm_parameters::testnet::BondPublicVerifier::METADATA, + crate::types::native::parameters::BondPublicProver::METADATA, + crate::types::native::parameters::BondPublicVerifier::METADATA, ) } @@ -80,8 +80,8 @@ impl Metadata { "bond_validator", "bondValidatorVerifier", "credits.aleo/bond_validator", - snarkvm_parameters::testnet::BondValidatorProver::METADATA, - snarkvm_parameters::testnet::BondValidatorVerifier::METADATA, + crate::types::native::parameters::BondValidatorProver::METADATA, + crate::types::native::parameters::BondValidatorVerifier::METADATA, ) } @@ -91,8 +91,8 @@ impl Metadata { "claim_unbond_public", "claimUnbondPublicVerifier", "credits.aleo/claim_unbond_public", - snarkvm_parameters::testnet::ClaimUnbondPublicProver::METADATA, - snarkvm_parameters::testnet::ClaimUnbondPublicVerifier::METADATA, + crate::types::native::parameters::ClaimUnbondPublicProver::METADATA, + crate::types::native::parameters::ClaimUnbondPublicVerifier::METADATA, ) } @@ -102,8 +102,8 @@ impl Metadata { "fee_private", "feePrivateVerifier", "credits.aleo/fee_private", - snarkvm_parameters::testnet::FeePrivateProver::METADATA, - snarkvm_parameters::testnet::FeePrivateVerifier::METADATA, + crate::types::native::parameters::FeePrivateProver::METADATA, + crate::types::native::parameters::FeePrivateVerifier::METADATA, ) } @@ -113,8 +113,8 @@ impl Metadata { "fee_public", "feePublicVerifier", "credits.aleo/fee_public", - snarkvm_parameters::testnet::FeePublicProver::METADATA, - snarkvm_parameters::testnet::FeePublicVerifier::METADATA, + crate::types::native::parameters::FeePublicProver::METADATA, + crate::types::native::parameters::FeePublicVerifier::METADATA, ) } @@ -124,8 +124,8 @@ impl Metadata { "inclusion", "inclusionVerifier", "inclusion", - snarkvm_parameters::testnet::InclusionProver::METADATA, - snarkvm_parameters::testnet::InclusionVerifier::METADATA, + crate::types::native::parameters::InclusionProver::METADATA, + crate::types::native::parameters::InclusionVerifier::METADATA, ) } @@ -135,8 +135,8 @@ impl Metadata { "join", "joinVerifier", "credits.aleo/join", - snarkvm_parameters::testnet::JoinProver::METADATA, - snarkvm_parameters::testnet::JoinVerifier::METADATA, + crate::types::native::parameters::JoinProver::METADATA, + crate::types::native::parameters::JoinVerifier::METADATA, ) } @@ -146,8 +146,8 @@ impl Metadata { "set_validator_state", "setValidatorStateVerifier", "credits.aleo/set_validator_state", - snarkvm_parameters::testnet::SetValidatorStateProver::METADATA, - snarkvm_parameters::testnet::SetValidatorStateVerifier::METADATA, + crate::types::native::parameters::SetValidatorStateProver::METADATA, + crate::types::native::parameters::SetValidatorStateVerifier::METADATA, ) } @@ -157,8 +157,8 @@ impl Metadata { "split", "splitVerifier", "credits.aleo/split", - snarkvm_parameters::testnet::SplitProver::METADATA, - snarkvm_parameters::testnet::SplitVerifier::METADATA, + crate::types::native::parameters::SplitProver::METADATA, + crate::types::native::parameters::SplitVerifier::METADATA, ) } @@ -168,8 +168,8 @@ impl Metadata { "transfer_private", "transferPrivateVerifier", "credits.aleo/transfer_private", - snarkvm_parameters::testnet::TransferPrivateProver::METADATA, - snarkvm_parameters::testnet::TransferPrivateVerifier::METADATA, + crate::types::native::parameters::TransferPrivateProver::METADATA, + crate::types::native::parameters::TransferPrivateVerifier::METADATA, ) } @@ -179,8 +179,8 @@ impl Metadata { "transfer_private_to_public", "transferPrivateToPublicVerifier", "credits.aleo/transfer_private_to_public", - snarkvm_parameters::testnet::TransferPrivateToPublicProver::METADATA, - snarkvm_parameters::testnet::TransferPrivateToPublicVerifier::METADATA, + crate::types::native::parameters::TransferPrivateToPublicProver::METADATA, + crate::types::native::parameters::TransferPrivateToPublicVerifier::METADATA, ) } @@ -190,8 +190,8 @@ impl Metadata { "transfer_public", "transferPublicVerifier", "credits.aleo/transfer_public", - snarkvm_parameters::testnet::TransferPublicProver::METADATA, - snarkvm_parameters::testnet::TransferPublicVerifier::METADATA, + crate::types::native::parameters::TransferPublicProver::METADATA, + crate::types::native::parameters::TransferPublicVerifier::METADATA, ) } @@ -201,8 +201,8 @@ impl Metadata { "transfer_public_as_signer", "transferPublicAsSignerVerifier", "credits.aleo/transfer_public_as_signer", - snarkvm_parameters::testnet::TransferPublicAsSignerProver::METADATA, - snarkvm_parameters::testnet::TransferPublicAsSignerVerifier::METADATA, + crate::types::native::parameters::TransferPublicAsSignerProver::METADATA, + crate::types::native::parameters::TransferPublicAsSignerVerifier::METADATA, ) } @@ -212,8 +212,8 @@ impl Metadata { "transfer_public_to_private", "transferPublicToPrivateVerifier", "credits.aleo/transfer_public_to_private", - snarkvm_parameters::testnet::TransferPublicToPrivateProver::METADATA, - snarkvm_parameters::testnet::TransferPublicToPrivateVerifier::METADATA, + crate::types::native::parameters::TransferPublicToPrivateProver::METADATA, + crate::types::native::parameters::TransferPublicToPrivateVerifier::METADATA, ) } @@ -223,8 +223,8 @@ impl Metadata { "unbond_public", "unbondPublicVerifier", "credits.aleo/unbond_public", - snarkvm_parameters::testnet::UnbondPublicProver::METADATA, - snarkvm_parameters::testnet::UnbondPublicVerifier::METADATA, + crate::types::native::parameters::UnbondPublicProver::METADATA, + crate::types::native::parameters::UnbondPublicVerifier::METADATA, ) } } diff --git a/wasm/src/programs/verifying_key/mod.rs b/wasm/src/programs/verifying_key/mod.rs index 72bd0aef1..f4a9020bc 100644 --- a/wasm/src/programs/verifying_key/mod.rs +++ b/wasm/src/programs/verifying_key/mod.rs @@ -121,63 +121,69 @@ mod tests { use super::*; use wasm_bindgen_test::*; + #[cfg(feature = "testnet")] const TRANSFER_PUBLIC_VERIFYING_KEY: &str = "verifier1qygqqqqqqqqqqqp3xqqqqqqqqqqzvvqqqqqqqqqq23hqqqqqqqqqqau5qqqqqqqqqq5yzqqqqqqqqqqvqqqqqqqqqqqz2rh4q6m4u0ycv2z5qx95echpdcsktezkr2j9cvff0dngp45jfqggm8q3578nkhjudslm2rdpsgcpks4ulquyqrtd978zvj65pxmhkudyjtj005h66jcnwg3f6mdqqaqjed3avcz599kth8a3nak0tftsrk4hczcdvlmrdnzsa6rfppy72flsrhdhn6npxfxt2rrudk8jrk5fefkawhhrf0psccp6l9akckaps898v5mk7vprkx90gg798d6j5tvvtma0r9phq3jndan5rkwv8wmkngeha3pzrjzslkt8ct9umm4wfq8dhnpdv8m4plq70c3d6wxs4l3cv4gyqhgjtwfuydc5fflulwgjvdtaxxlmpf0l5n800jn2lwnt5kqqtdsx2lvzl3kw3ns5hnsu4jzg9ejptg7n7r7d9dvqsrvldw9paeq86hjxeaac6typemynwzt8w3vq3e27l4swd9aqxaas7zsy5mw7ftnjct9jq6t9rdq0kx8vjag77nt0z894xqkrfp27hehk83nfcg7cpjcc7f8mznga33xp36seafxpn26rq4w5l9uawtx02mzpq9kuyyx7nvhtad0mxk5su659xx5wv3yhqqy3577kwc40spvp9dst59ap2ll5uuq7qaauy9vy5yvrjd77c443evxrwfsee8jg5hvt6f9xaupjzq2cmuuwdvjs0qtxmnwjmdepu5979qy4nhqs63zljatt7kkggddxctt74crayt4djvnh3u6tjzm8wyqpc7nf0r0k9mp34x9musgdqegkmscey50ckyehm67c5tcdlawkh6my2v3xzwaug7c4y9xyw0dfkqup24jdckk5wxkyfd8rsp6h220dj786t54fyj59ehtq0gyut6lcattumgdss4kkchrdp7f5sjgcu7ycpzq0d47m6xe3yh2q5q76fa20lm46pe8fcd9yqcrxduhkdqfe4c9pw3pqqqqqqqqqq0qvtsl"; + #[cfg(feature = "mainnet")] + const TRANSFER_PUBLIC_VERIFYING_KEY: &str = "verifier1qygqqqqqqqqqqqp3xqqqqqqqqqqzvvqqqqqqqqqq23hqqqqqqqqqqau5qqqqqqqqqq5yzqqqqqqqqqqvqqqqqqqqqqqz2rh4q6m4u0ycv2z5qx95echpdcsktezkr2j9cvff0dngp45jfqggm8q3578nkhjudslm2rdpsgcpks4ulquyqrtd978zvj65pxmhkudyjtj005h66jcnwg3f6mdqqaqjed3avcz599kth8a3nak0tftsrk4hczcdvlmrdnzsa6rfppy72flsrhdhn6npxfxt2rrudk8jrk5fefkawhhrf0psccp6l9akckaps898v5mk7vprkx90gg798d6j5tvvtma0r9phq3jndan5rkwv8wmkngeha3pzrjzslkt8ct9umm4wfq8dhnpdv8m4plq70c3d6wxs4l3cv4gyqhgjtwfuydc5fflulwgjvdtaxxlmpf0l5n800jn2lwnt5kqqtdsx2lvzl3kw3ns5hnsu4jzg9ejptg7n7r7d9dvqsrvldw9paeq86hjxeaac6typemynwzt8w3vq3e27l4swd9aqxaas7zsy5mw7ftnjct9jq6t9rdq0kx8vjag77nt0z894xqkrfp27hehk83nfcg7cpjcc7f8mznga33xp36seafxpn26rq4w5l9uawtx02mzpq9kuyyx7nvhtad0mxk5su659xx5wv3yhqqy3577kwc40spvp9dst59ap2ll5uuq7qaauy9vy5yvrjd77c443evxrwfsee8jg5hvt6f9xaupjzqdd2jexnaselrezp7eptfjtpgs6ga5p3nkycwf26k6nkrf8j302e3a62rq7x5xpz9r8q9ttf36y3vqq6kvvmnuuzv6zkv0p8ds0g6z7stfhtxvzl4vjgj9vf35tnkxxvhmk4xgqcycz6g5aaejlmskvr8uq24jdckk5wxkyfd8rsp6h220dj786t54fyj59ehtq0gyut6lcattumgdss4kkchrdp7f5sjgcu7ycppt59jx985rpqa04krg2sh5je7dt6rntnvf2xd76vrgh3ldnp33lw3pqqqqqqqqqqjgex6x"; + #[allow(dead_code)] #[test] fn verifying_key_strings() { let bond_public_verifier_string = - VerifyingKey::from_bytes(&snarkvm_parameters::testnet::BondPublicVerifier::load_bytes().unwrap()) - .unwrap() - .to_string(); - let claim_unbond_public_verifier_string = - VerifyingKey::from_bytes(&snarkvm_parameters::testnet::ClaimUnbondPublicVerifier::load_bytes().unwrap()) + VerifyingKey::from_bytes(&crate::types::native::parameters::BondPublicVerifier::load_bytes().unwrap()) .unwrap() .to_string(); + let claim_unbond_public_verifier_string = VerifyingKey::from_bytes( + &crate::types::native::parameters::ClaimUnbondPublicVerifier::load_bytes().unwrap(), + ) + .unwrap() + .to_string(); let fee_private_verifier_string = - VerifyingKey::from_bytes(&snarkvm_parameters::testnet::FeePrivateVerifier::load_bytes().unwrap()) + VerifyingKey::from_bytes(&crate::types::native::parameters::FeePrivateVerifier::load_bytes().unwrap()) .unwrap() .to_string(); let fee_public_verifier_string = - VerifyingKey::from_bytes(&snarkvm_parameters::testnet::FeePublicVerifier::load_bytes().unwrap()) + VerifyingKey::from_bytes(&crate::types::native::parameters::FeePublicVerifier::load_bytes().unwrap()) .unwrap() .to_string(); let inclusion_verifier_string = - VerifyingKey::from_bytes(&snarkvm_parameters::testnet::InclusionVerifier::load_bytes().unwrap()) + VerifyingKey::from_bytes(&crate::types::native::parameters::InclusionVerifier::load_bytes().unwrap()) .unwrap() .to_string(); let join_verifier_string = - VerifyingKey::from_bytes(&snarkvm_parameters::testnet::JoinVerifier::load_bytes().unwrap()) - .unwrap() - .to_string(); - let set_validator_state_verifier_string = - VerifyingKey::from_bytes(&snarkvm_parameters::testnet::SetValidatorStateVerifier::load_bytes().unwrap()) + VerifyingKey::from_bytes(&crate::types::native::parameters::JoinVerifier::load_bytes().unwrap()) .unwrap() .to_string(); + let set_validator_state_verifier_string = VerifyingKey::from_bytes( + &crate::types::native::parameters::SetValidatorStateVerifier::load_bytes().unwrap(), + ) + .unwrap() + .to_string(); let split_verifier_string = - VerifyingKey::from_bytes(&snarkvm_parameters::testnet::SplitVerifier::load_bytes().unwrap()) + VerifyingKey::from_bytes(&crate::types::native::parameters::SplitVerifier::load_bytes().unwrap()) .unwrap() .to_string(); let transfer_private_verifier_string = - VerifyingKey::from_bytes(&snarkvm_parameters::testnet::TransferPrivateVerifier::load_bytes().unwrap()) + VerifyingKey::from_bytes(&crate::types::native::parameters::TransferPrivateVerifier::load_bytes().unwrap()) .unwrap() .to_string(); let transfer_private_to_public_verifier_string = VerifyingKey::from_bytes( - &snarkvm_parameters::testnet::TransferPrivateToPublicVerifier::load_bytes().unwrap(), + &crate::types::native::parameters::TransferPrivateToPublicVerifier::load_bytes().unwrap(), ) .unwrap() .to_string(); let transfer_public_verifier_string = - VerifyingKey::from_bytes(&snarkvm_parameters::testnet::TransferPublicVerifier::load_bytes().unwrap()) + VerifyingKey::from_bytes(&crate::types::native::parameters::TransferPublicVerifier::load_bytes().unwrap()) .unwrap() .to_string(); let transfer_public_to_private_verifier_string = VerifyingKey::from_bytes( - &snarkvm_parameters::testnet::TransferPublicToPrivateVerifier::load_bytes().unwrap(), + &crate::types::native::parameters::TransferPublicToPrivateVerifier::load_bytes().unwrap(), ) .unwrap() .to_string(); let unbond_public_verifier_string = - VerifyingKey::from_bytes(&snarkvm_parameters::testnet::UnbondPublicVerifier::load_bytes().unwrap()) + VerifyingKey::from_bytes(&crate::types::native::parameters::UnbondPublicVerifier::load_bytes().unwrap()) .unwrap() .to_string(); println!("bond_public_verifier:\nverifying_key: \"{}\"", bond_public_verifier_string); @@ -203,7 +209,8 @@ mod tests { #[wasm_bindgen_test] async fn test_verifying_key_roundtrip() { - let transfer_public_verifier_bytes = snarkvm_parameters::testnet::TransferPublicVerifier::load_bytes().unwrap(); + let transfer_public_verifier_bytes = + crate::types::native::parameters::TransferPublicVerifier::load_bytes().unwrap(); let transfer_public_verifier = VerifyingKey::from_bytes(&transfer_public_verifier_bytes).unwrap(); let transfer_public_verifying_key_string = transfer_public_verifier.to_string(); assert_eq!(transfer_public_verifying_key_string, TRANSFER_PUBLIC_VERIFYING_KEY); @@ -211,12 +218,17 @@ mod tests { #[wasm_bindgen_test] async fn test_verifier_checksum() { - let transfer_public_verifier_bytes = snarkvm_parameters::testnet::TransferPublicVerifier::load_bytes().unwrap(); + let transfer_public_verifier_bytes = + crate::types::native::parameters::TransferPublicVerifier::load_bytes().unwrap(); let transfer_public_verifier = VerifyingKey::from_bytes(&transfer_public_verifier_bytes).unwrap(); let transfer_public_verifying_key_checksum = transfer_public_verifier.checksum(); - assert_eq!( - transfer_public_verifying_key_checksum, - "1b5109468e7992c39bbbc299dd1f94f18e49928e253e60ed68c7d9f02e73fe8d" - ); + + #[cfg(feature = "testnet")] + let checksum = "1b5109468e7992c39bbbc299dd1f94f18e49928e253e60ed68c7d9f02e73fe8d"; + + #[cfg(feature = "mainnet")] + let checksum = "ea77f42a35b3f891e7753c7333df365f356883550c4602df11f270237bef340d"; + + assert_eq!(transfer_public_verifying_key_checksum, checksum); } } diff --git a/wasm/src/types/mod.rs b/wasm/src/types/mod.rs index 5ea17e8d2..2e5972453 100644 --- a/wasm/src/types/mod.rs +++ b/wasm/src/types/mod.rs @@ -17,4 +17,6 @@ pub mod field; pub use field::*; +mod networks; + pub(crate) mod native; diff --git a/wasm/src/types/native.rs b/wasm/src/types/native.rs index 573dc4c2f..0533c489b 100644 --- a/wasm/src/types/native.rs +++ b/wasm/src/types/native.rs @@ -14,10 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Aleo SDK library. If not, see . -pub use snarkvm_circuit_network::AleoTestnetV0; +pub use super::networks::*; + pub use snarkvm_console::{ account::{Address, PrivateKey, Signature, ViewKey}, - network::{Network, TestnetV0}, + network::Network, program::{ Ciphertext, Entry, @@ -58,10 +59,6 @@ pub type ViewKeyNative = ViewKey; // Algebraic types pub type FieldNative = Field; -// Network types -pub type CurrentNetwork = TestnetV0; -pub type CurrentAleo = AleoTestnetV0; - // Record types pub type CiphertextNative = Ciphertext; pub type PlaintextNative = Plaintext; diff --git a/wasm/src/types/networks/mainnet.rs b/wasm/src/types/networks/mainnet.rs new file mode 100644 index 000000000..ffd89a69b --- /dev/null +++ b/wasm/src/types/networks/mainnet.rs @@ -0,0 +1,23 @@ +// 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 . + +pub use snarkvm_circuit_network::AleoV0 as CurrentAleo; + +pub use snarkvm_console::network::MainnetV0 as CurrentNetwork; + +pub use snarkvm_parameters::mainnet as parameters; + +pub const BASE_URL: &'static str = "https://parameters.aleo.org/mainnet/"; diff --git a/wasm/src/types/networks/mod.rs b/wasm/src/types/networks/mod.rs new file mode 100644 index 000000000..7cb8f0e43 --- /dev/null +++ b/wasm/src/types/networks/mod.rs @@ -0,0 +1,27 @@ +// 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 . + +#[cfg(feature = "testnet")] +mod testnet; + +#[cfg(feature = "testnet")] +pub use testnet::*; + +#[cfg(feature = "mainnet")] +mod mainnet; + +#[cfg(feature = "mainnet")] +pub use mainnet::*; diff --git a/wasm/src/types/networks/testnet.rs b/wasm/src/types/networks/testnet.rs new file mode 100644 index 000000000..9085dc799 --- /dev/null +++ b/wasm/src/types/networks/testnet.rs @@ -0,0 +1,23 @@ +// 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 . + +pub use snarkvm_circuit_network::AleoTestnetV0 as CurrentAleo; + +pub use snarkvm_console::network::TestnetV0 as CurrentNetwork; + +pub use snarkvm_parameters::testnet as parameters; + +pub const BASE_URL: &'static str = "https://parameters.aleo.org/testnet/"; diff --git a/wasm/test.js b/wasm/test.js index 4ac12120f..ff1b1b4f5 100644 --- a/wasm/test.js +++ b/wasm/test.js @@ -6,8 +6,10 @@ const file = $fs.readFileSync("package.json", { encoding: "utf8" }); $fs.writeFileSync("package.json", file.replace(/"type": "module",/g, "")); try { - $child.execSync("wasm-pack test --node", { - stdio: "inherit", + ["testnet", "mainnet"].forEach((network) => { + $child.execSync(`wasm-pack test --node --features ${network}`, { + stdio: "inherit", + }); }); } finally { diff --git a/wasm/tests/offchain.rs b/wasm/tests/offchain.rs index cae5eaebf..757c1d540 100644 --- a/wasm/tests/offchain.rs +++ b/wasm/tests/offchain.rs @@ -158,7 +158,7 @@ async fn test_fee_validation() { inputs, 100.0, Some(fee_record.clone()), - Some("https://api.explorer.aleo.org/v1".to_string()), + Some("https://api.explorer.provable.com/v1".to_string()), None, None, None, @@ -175,7 +175,7 @@ async fn test_fee_validation() { &Program::get_credits_program().to_string(), 100.0, Some(fee_record.clone()), - Some("https://api.explorer.aleo.org/v1".to_string()), + Some("https://api.explorer.provable.com/v1".to_string()), None, None, None, @@ -193,7 +193,7 @@ async fn test_fee_validation() { Some(fee_record.clone()), 0.9, Some(fee_record.clone()), - Some("https://api.explorer.aleo.org/v1".to_string()), + Some("https://api.explorer.provable.com/v1".to_string()), None, None, None, @@ -211,7 +211,7 @@ async fn test_fee_validation() { Some(fee_record.clone()), 100.00, Some(fee_record.clone()), - Some("https://api.explorer.aleo.org/v1".to_string()), + Some("https://api.explorer.provable.com/v1".to_string()), None, None, None, @@ -228,7 +228,7 @@ async fn test_fee_validation() { fee_record.clone(), 100.00, Some(fee_record.clone()), - Some("https://api.explorer.aleo.org/v1".to_string()), + Some("https://api.explorer.provable.com/v1".to_string()), None, None, None, @@ -264,7 +264,7 @@ async fn test_fee_estimation() { FINALIZE, "integer_key_mapping_update", inputs, - Some("https://api.explorer.aleo.org/v1".to_string()), + Some("https://api.explorer.provable.com/v1".to_string()), None, None, None, diff --git a/website/README.md b/website/README.md index 6a591568e..994ed2090 100644 --- a/website/README.md +++ b/website/README.md @@ -11,8 +11,8 @@ This project was bootstrapped with [Vite](https://vitejs.dev/). - Install [wasm-pack](https://rustwasm.github.io/wasm-pack/installer/) ```bash -rustup toolchain install nightly-2023-05-24 -rustup component add rust-src --toolchain nightly-2023-05-24 +rustup toolchain install nightly-2024-07-21 +rustup component add rust-src --toolchain nightly-2024-07-21 yarn yarn dev ``` diff --git a/website/src/pages/Homepage.jsx b/website/src/pages/Homepage.jsx index 5534bdf84..44e51f674 100644 --- a/website/src/pages/Homepage.jsx +++ b/website/src/pages/Homepage.jsx @@ -18,7 +18,7 @@ const Homepage = () => { The tooling for building zero-knowledge applications at your fingertips

{" "} -
+
{ See Docs {" "} {" "} -
+
    {" "} diff --git a/website/src/pages/TermsOfUse.jsx b/website/src/pages/TermsOfUse.jsx index 732532797..ecfc004c6 100644 --- a/website/src/pages/TermsOfUse.jsx +++ b/website/src/pages/TermsOfUse.jsx @@ -858,7 +858,7 @@ const TermsOfUse = () => { version of the Terms is the original, governing instrument of the understanding between you and us. In the event of any conflict between the English version of these Terms and any - translation, the English version will prevail. + translation, the English version will prevail.

    13.2 Arbitration

    @@ -878,7 +878,7 @@ const TermsOfUse = () => { indirectly, as a User or consumer (each, a “Claim,” and, collectively, “Claims”). This Arbitration Agreement will apply, without limitation, to all Claims that arose or were asserted - before or after your consent to these Terms. + before or after your consent to these Terms.

    (b) Opting Out of Arbitration Agreement. If you are a new User, you can reject and @@ -942,7 +942,7 @@ const TermsOfUse = () => { PREVENTING YOU FROM ASSERTING CLAIMS IN A SMALL CLAIMS COURT, PROVIDED THAT YOUR CLAIMS QUALIFY AND SO LONG AS THE MATTER REMAINS IN SUCH COURT AND ADVANCES ON ONLY AN INDIVIDUAL - (NON-CLASS, NON-COLLECTIVE, AND NON-REPRESENTATIVE) BASIS. + (NON-CLASS, NON-COLLECTIVE, AND NON-REPRESENTATIVE) BASIS.

    (E) Severability. If this Arbitration Agreement is found to be void, @@ -965,7 +965,7 @@ const TermsOfUse = () => { the parties agree that litigation of any dispute regarding the entitlement to public injunctive relief will be stayed pending the outcome of any individual claims in arbitration.

    - +

    13.3 Class Action/Jury Trial Waiver. BY ENTERING INTO THESE TERMS, @@ -982,11 +982,11 @@ const TermsOfUse = () => { PROVABLE AGREE THAT THE ARBITRATOR MAY AWARD RELIEF ONLY TO AN INDIVIDUAL CLAIMANT AND ONLY TO THE EXTENT NECESSARY TO PROVIDE RELIEF ON YOUR INDIVIDUAL CLAIM(S). ANY RELIEF AWARDED MAY NOT - AFFECT OTHER USERS. - + AFFECT OTHER USERS. +

    - 14. U.S. Government Restricted Rights + 14. U.S. Government Restricted Rights

    To the extent the Platform is being used by or on behalf of the U.S. @@ -997,11 +997,11 @@ const TermsOfUse = () => { rights with respect to the Platform as are granted to all other Users hereunder, in accordance with 48 C.F.R. §227.7202 and 48 C.F.R. §12.212, as applicable. - +

    15. Export Controls, Sanctions - and Anti-Money Laundering -

    + and Anti-Money Laundering +

    You understand and acknowledge that the Platform may be subject to export control laws and regulations. You will comply with all applicable import and @@ -1011,8 +1011,8 @@ const TermsOfUse = () => { and economic sanctions maintained by the U.S. Treasury Department’s Office of Foreign Assets Control (“OFAC”), and the International Traffic in Arms Regulations maintained by the U.S. - State Department. You represent and warrant that: - + State Department. You represent and warrant that: +

    (a) You will not access the Platform from any country, region, territory or jurisdiction that is the target of comprehensive territorial or @@ -1020,26 +1020,26 @@ const TermsOfUse = () => { region, territory or jurisdiction a “Sanctioned Country”), which, as of the time of this Agreement, are Crimea, Cuba, Iran, North Korea, Syria, the so-called Donetsk People’s Republic, and - the so-called Luhansk People’s Republic; + the so-called Luhansk People’s Republic;

    - +

    (b) You will not provide access to the Platform to any person that is, or that is owned or controlled by a person that is, the target of any sanctions administered or enforced by OFAC or the U.S. Department of State,(collectively, “Sanctions”) or that is - located, organized or resident in any Sanctioned Country; + located, organized or resident in any Sanctioned Country;

    (c) None of you, your subsidiaries, directors, officers, employees, agents or affiliates is a person that is, or is owned or - controlled by persons that are, the target of any Sanctions; + controlled by persons that are, the target of any Sanctions;

    (d) None of you, your subsidiaries, directors, officers, employees, agents or affiliates are located, organized, or resident in, or owned or controlled by persons that are located, organized or - resident in a Sanctioned Country; 14 + resident in a Sanctioned Country; 14

    (e) You will not utilize the Platform in any manner that, directly or directly, conducts, @@ -1047,7 +1047,7 @@ const TermsOfUse = () => { person that is the target of Sanctions or is located, organized or resident in a Sanctioned Country or in any other manner that would result in a violation of Sanctions by any person, - including Provable; + including Provable;

    (f) You will not utilize the Platform in any manner that, directly or indirectly, conducts, facilitates, @@ -1057,13 +1057,13 @@ const TermsOfUse = () => { of any applicable law, rule or regulation of any jurisdiction concerning or relating to anti-money laundering, including the USA PATRIOT Act of 2001, as amended (“Anti-Money Laundering - Laws”); and + Laws”); and

    (g) You have conducted and will conduct all activities generating funds, assets or other items of value introduced to the Platform in compliance with applicable - Anti-Money Laundering Laws and Sanctions. + Anti-Money Laundering Laws and Sanctions.

    - +

    16. General Provisions

    16.1 Assignment. These Terms, and any rights and licenses granted hereunder, may not be transferred or assigned by you @@ -1071,7 +1071,7 @@ const TermsOfUse = () => { by us without restriction. Any attempted transfer or assignment in violation hereof will be null and void.

    - +

    16.2 Notification Procedures and Changes to these Terms. We may provide notifications, whether such notifications are required by @@ -1111,7 +1111,7 @@ const TermsOfUse = () => { deemed invalid by a court of competent jurisdiction, the invalidity of such provision will not affect the validity of the remaining provisions of these Terms, which will remain in full - force and effect. + force and effect.

    16.4 Interpretation. For purposes of these Terms, (a) the words “include,” “includes” and “including” are @@ -1133,7 +1133,7 @@ const TermsOfUse = () => { these Terms will be deemed a further or continuing waiver of such term or of any other term, and our failure to assert any right or provision under these Terms will not constitute a - waiver of such right or provision. + waiver of such right or provision.

    16.6 California Residents. The provider of the Platform is: Provable Inc., 5470 Kietzke Lane, STE 300, Reno, NV 89511. If you are a California resident, @@ -1142,7 +1142,7 @@ const TermsOfUse = () => { Consumer Services of the California Department of Consumer Affairs by contacting it in writing at 1625 North Market Blvd., Suite N 112 Sacramento, CA 95834, or by telephone at (800) - 952-5210 or (916) 445-1254. + 952-5210 or (916) 445-1254.

    16.7 Contact. If you have any questions about these Terms and/or the Platform, please contact us at termsofuse@provable.com. diff --git a/website/src/setupTests.js b/website/src/setupTests.js deleted file mode 100644 index 1dd407a63..000000000 --- a/website/src/setupTests.js +++ /dev/null @@ -1,5 +0,0 @@ -// jest-dom adds custom jest matchers for asserting on DOM nodes. -// allows you to do things like: -// expect(element).toHaveTextContent(/react/i) -// learn more: https://github.com/testing-library/jest-dom -import "@testing-library/jest-dom"; diff --git a/website/src/tabs/develop/Deploy.jsx b/website/src/tabs/develop/Deploy.jsx index fae726a07..c0a749ffe 100644 --- a/website/src/tabs/develop/Deploy.jsx +++ b/website/src/tabs/develop/Deploy.jsx @@ -16,10 +16,10 @@ import { CodeEditor } from "./execute/CodeEditor.jsx"; import axios from "axios"; export const Deploy = () => { - + const [form] = Form.useForm(); const [deploymentFeeRecord, setDeploymentFeeRecord] = useState(null); - const [deployUrl, setDeployUrl] = useState("https://api.explorer.aleo.org/v1"); + const [deployUrl, setDeployUrl] = useState("https://api.explorer.provable.com/v1"); const [deploymentFee, setDeploymentFee] = useState("1"); const [loading, setLoading] = useState(false); const [feeLoading, setFeeLoading] = useState(false); @@ -227,7 +227,7 @@ export const Deploy = () => { } >

    {