Skip to content

Commit

Permalink
Converting to use rollup-plugin-rust instead of wasm-pack
Browse files Browse the repository at this point in the history
  • Loading branch information
iamalwaysuncomfortable authored Oct 5, 2023
2 parents f7753d1 + 0ce0f9e commit 02271c7
Show file tree
Hide file tree
Showing 39 changed files with 1,231 additions and 486 deletions.
24 changes: 24 additions & 0 deletions create-aleo-app/template-node/_gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
34 changes: 34 additions & 0 deletions create-aleo-app/template-node/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {Account, initThreadPool, PrivateKey, ProgramManager,} from "@aleohq/sdk";

await initThreadPool(10);

const hello_hello_program =
"program hello_hello.aleo;\n" +
"\n" +
"function hello:\n" +
" input r0 as u32.public;\n" +
" input r1 as u32.private;\n" +
" add r0 r1 into r2;\n" +
" output r2 as u32.private;\n";

async function localProgramExecution(program, aleoFunction, inputs) {
const programManager = new ProgramManager();

// Create a temporary account for the execution of the program
const account = new Account();
programManager.setAccount(account);

const executionResponse = await programManager.executeOffline(
hello_hello_program,
"hello",
["5u32", "5u32"],
false,
);
return executionResponse.getOutputs();
}

const start = Date.now();
console.log("Starting execute!");
const result = await localProgramExecution();
console.log(result);
console.log("Execute finished!", Date.now() - start);
12 changes: 12 additions & 0 deletions create-aleo-app/template-node/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "node-starter",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"start": "node index.js"
},
"dependencies": {
"@aleohq/sdk": "^0.5.10"
}
}
1 change: 1 addition & 0 deletions create-aleo-app/template-vanilla/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"devDependencies": {
"@aleohq/sdk": "^0.5.10",
"tslib": "^2.6.2",
"vite": "^4.4.5"
}
}
28 changes: 18 additions & 10 deletions sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,23 @@
"The Aleo Team <[email protected]>"
],
"license": "GPL-3.0",
"main": "./dist/index.js",
"browser": "./dist/index.js",
"types": "./dist/index.d.ts",
"type": "module",
"main": "./dist/node.js",
"browser": "./dist/index.js",
"exports": {
".": {
"node": "./dist/node.js",
"default": "./dist/index.js"
}
},
"files": [
"dist",
"LICENSE",
"README.md"
],
"scripts": {
"build": "rollup -c rollup.config.node.js",
"build:browser": "rollup -c rollup.config.browser.js",
"build": "rimraf dist && rollup -c rollup.config.js",
"prepublish": "npm run build",
"clear_jest": "jest --clearCache",
"dev": "tsc --watch",
"test": "jest --config jest-config.json",
Expand All @@ -38,27 +43,30 @@
},
"homepage": "https://github.com/AleoHQ/sdk#readme",
"dependencies": {
"@aleohq/nodejs": "0.5.10",
"@aleohq/wasm": "0.5.10",
"@aleohq/wasm": "^0.6.0",
"axios": "^1.1.3",
"comlink": "^4.4.1",
"jsdoc": "^3.6.11",
"unfetch": "^5.0.0"
"mime": "^3.0.0",
"sync-request": "^6.1.0"
},
"devDependencies": {
"@types/jest": "^29.4.0",
"@types/mime": "^3.0.1",
"@typescript-eslint/eslint-plugin": "^5.41.0",
"@typescript-eslint/parser": "^5.41.0",
"better-docs": "^2.7.2",
"clean-jsdoc-theme": "^4.1.8",
"cpr": "^3.0.1",
"eslint": "^8.26.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"jest": "^29.4.2",
"prettier": "2.7.1",
"rimraf": "^5.0.1",
"rollup": "^3.27.2",
"rollup-plugin-typescript2": "^0.35.0",
"rollup-plugin-typescript2": "^0.36.0",
"ts-jest": "^29.0.5",
"typescript": "^4.8.4"
"typescript": "^5.2.2"
}
}
21 changes: 0 additions & 21 deletions sdk/rollup.config.browser.js

This file was deleted.

34 changes: 34 additions & 0 deletions sdk/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import typescript from "rollup-plugin-typescript2";

export default {
input: {
index: "./src/index.ts",
thread: "./src/thread.ts",
worker: "./src/worker.ts",
node: "./src/node.ts",
"node-polyfill": "./src/node-polyfill.ts",
},
output: {
dir: `dist`,
format: "es",
sourcemap: true,
},
external: [
"node:worker_threads",
"node:os",
"node:fs",
"node:crypto",
"mime/lite.js",
"sync-request",
"axios",
"comlink",
"@aleohq/wasm",
"@aleohq/wasm/worker.js",
],
plugins: [
typescript({
tsconfig: "tsconfig.json",
clean: true,
}),
],
};
21 changes: 0 additions & 21 deletions sdk/rollup.config.node.js

This file was deleted.

2 changes: 1 addition & 1 deletion sdk/src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
ViewKey,
PrivateKeyCiphertext,
RecordCiphertext,
} from ".";
} from "./index";

interface AccountParam {
privateKey?: string;
Expand Down
47 changes: 0 additions & 47 deletions sdk/src/browser.ts

This file was deleted.

2 changes: 1 addition & 1 deletion sdk/src/function-key-provider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ProvingKey, VerifyingKey, CREDITS_PROGRAM_KEYS, KEY_STORE, PRIVATE_TRANSFER, PRIVATE_TO_PUBLIC_TRANSFER, PUBLIC_TRANSFER, PUBLIC_TO_PRIVATE_TRANSFER} from ".";
import { ProvingKey, VerifyingKey, CREDITS_PROGRAM_KEYS, KEY_STORE, PRIVATE_TRANSFER, PRIVATE_TO_PUBLIC_TRANSFER, PUBLIC_TRANSFER, PUBLIC_TO_PRIVATE_TRANSFER} from "./index";
import axios from 'axios';

type FunctionKeyPair = [ProvingKey, VerifyingKey];
Expand Down
51 changes: 44 additions & 7 deletions sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,49 @@ import {
RecordSearchParams,
} from "./record-provider";

import { initThreadPool as wasmInitThreadPool } from "@aleohq/wasm";


// @TODO: This function is no longer needed, remove it.
async function initializeWasm() {
console.warn("initializeWasm is deprecated, you no longer need to use it");
}

/**
* Initializes a thread pool of Workers. This enables multi-threading, which significantly improves performance.
*/
async function initThreadPool(threads: number) {
await wasmInitThreadPool(new URL("thread.js", import.meta.url), threads);
}


export { createAleoWorker } from "./managed-worker";

export { ProgramManager } from "./program-manager";

export {
PrivateKey,
ViewKey,
Address,
Private,
PrivateKeyCiphertext,
RecordCiphertext,
Signature,
ProvingKey,
VerifyingKey,
Program,
RecordPlaintext,
Transaction as WasmTransaction,
ExecutionResponse,
ProgramManager as ProgramManagerBase,
verifyFunctionExecution,
} from "@aleohq/wasm";

export {
initializeWasm,
initThreadPool,
};

export {
Account,
AleoKeyProvider,
Expand Down Expand Up @@ -150,10 +193,4 @@ export {
PUBLIC_TO_PRIVATE_TRANSFER,
VALID_TRANSFER_TYPES,
logAndThrow,
};

// If using the SDK in a browser context, uncomment this line and run `npm run build:browser`
// export * from './browser';

// The following imports and exports are for a NodeJS context - if using the SDK in a browser context, delete or comment out this line
export * from './node';
};
4 changes: 2 additions & 2 deletions sdk/src/network-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
Transaction,
Transition,
logAndThrow
} from ".";
} from "./index";

type ProgramImports = { [key: string]: string | Program };

Expand Down Expand Up @@ -617,4 +617,4 @@ class AleoNetworkClient {
}
}

export { AleoNetworkClient, ProgramImports }
export { AleoNetworkClient, ProgramImports }
8 changes: 8 additions & 0 deletions sdk/src/node-polyfill.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import "./polyfill/crypto";
import "./polyfill/fetch";
import "./polyfill/xmlhttprequest";
import "./polyfill/worker";

if (!globalThis.self) {
(globalThis as any).self = globalThis;
}
Loading

0 comments on commit 02271c7

Please sign in to comment.