chore: rm wasm serialization checks (#890) #39
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Publish EZKL Engine npm package | |
on: | |
workflow_dispatch: | |
inputs: | |
tag: | |
description: "The tag to release" | |
required: true | |
push: | |
tags: | |
- "*" | |
defaults: | |
run: | |
working-directory: . | |
jobs: | |
publish-wasm-bindings: | |
name: publish-wasm-bindings | |
runs-on: ubuntu-latest | |
if: startsWith(github.ref, 'refs/tags/') | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions-rs/toolchain@v1 | |
with: | |
toolchain: nightly-2024-07-18 | |
override: true | |
components: rustfmt, clippy | |
- uses: jetli/[email protected] | |
with: | |
# Pin to version 0.12.1 | |
version: 'v0.12.1' | |
- name: Add wasm32-unknown-unknown target | |
run: rustup target add wasm32-unknown-unknown | |
- name: Add rust-src | |
run: rustup component add rust-src --toolchain nightly-2024-07-18-x86_64-unknown-linux-gnu | |
- name: Install binaryen | |
run: | | |
set -e | |
curl -L https://github.com/WebAssembly/binaryen/releases/download/version_116/binaryen-version_116-x86_64-linux.tar.gz | tar xzf - | |
export PATH=$PATH:$PWD/binaryen-version_116/bin | |
wasm-opt --version | |
- name: Build wasm files for both web and nodejs compilation targets | |
run: | | |
wasm-pack build --release --target nodejs --out-dir ./pkg/nodejs . -- -Z build-std="panic_abort,std" | |
wasm-pack build --release --target web --out-dir ./pkg/web . -- -Z build-std="panic_abort,std" --features web | |
- name: Create package.json in pkg folder | |
shell: bash | |
env: | |
RELEASE_TAG: ${{ github.ref_name }} | |
run: | | |
echo '{ | |
"name": "@ezkljs/engine", | |
"version": "${{ github.ref_name }}", | |
"dependencies": { | |
"@types/json-bigint": "^1.0.1", | |
"json-bigint": "^1.0.0" | |
}, | |
"files": [ | |
"nodejs/ezkl_bg.wasm", | |
"nodejs/ezkl.js", | |
"nodejs/ezkl.d.ts", | |
"nodejs/package.json", | |
"nodejs/utils.js", | |
"web/ezkl_bg.wasm", | |
"web/ezkl.js", | |
"web/ezkl.d.ts", | |
"web/snippets/**/*", | |
"web/package.json", | |
"web/utils.js", | |
"ezkl.d.ts" | |
], | |
"main": "nodejs/ezkl.js", | |
"module": "web/ezkl.js", | |
"types": "nodejs/ezkl.d.ts", | |
"sideEffects": [ | |
"web/snippets/*" | |
] | |
}' > pkg/package.json | |
- name: Replace memory definition in nodejs | |
run: | | |
sed -i "3s|.*|imports['env'] = {memory: new WebAssembly.Memory({initial:20,maximum:65536,shared:true})}|" pkg/nodejs/ezkl.js | |
- name: Replace `import.meta.url` with `import.meta.resolve` definition in workerHelpers.js | |
run: | | |
find ./pkg/web/snippets -type f -name "*.js" -exec sed -i "s|import.meta.url|import.meta.resolve|" {} + | |
- name: Add serialize and deserialize methods to nodejs bundle | |
run: | | |
echo ' | |
const JSONBig = require("json-bigint"); | |
function deserialize(buffer) { // buffer is a Uint8ClampedArray | Uint8Array // return a JSON object | |
if (buffer instanceof Uint8ClampedArray) { | |
buffer = new Uint8Array(buffer.buffer); | |
} | |
const string = new TextDecoder().decode(buffer); | |
const jsonObject = JSONBig.parse(string); | |
return jsonObject; | |
} | |
function serialize(data) { // data is an object // return a Uint8ClampedArray | |
// Step 1: Stringify the Object with BigInt support | |
if (typeof data === "object") { | |
data = JSONBig.stringify(data); | |
} | |
// Step 2: Encode the JSON String | |
const uint8Array = new TextEncoder().encode(data); | |
// Step 3: Convert to Uint8ClampedArray | |
return new Uint8ClampedArray(uint8Array.buffer); | |
} | |
module.exports = { | |
deserialize, | |
serialize | |
}; | |
' > pkg/nodejs/utils.js | |
- name: Add serialize and deserialize methods to web bundle | |
run: | | |
echo ' | |
import { parse, stringify } from "json-bigint"; | |
export function deserialize(buffer) { // buffer is a Uint8ClampedArray | Uint8Array // return a JSON object | |
if (buffer instanceof Uint8ClampedArray) { | |
buffer = new Uint8Array(buffer.buffer); | |
} | |
const string = new TextDecoder().decode(buffer); | |
const jsonObject = parse(string); | |
return jsonObject; | |
} | |
export function serialize(data) { // data is an object // return a Uint8ClampedArray | |
// Step 1: Stringify the Object with BigInt support | |
if (typeof data === "object") { | |
data = stringify(data); | |
} | |
// Step 2: Encode the JSON String | |
const uint8Array = new TextEncoder().encode(data); | |
// Step 3: Convert to Uint8ClampedArray | |
return new Uint8ClampedArray(uint8Array.buffer); | |
} | |
' > pkg/web/utils.js | |
- name: Expose serialize and deserialize imports in nodejs target | |
run: | | |
sed -i '53i// import serialize and deserialize from utils.js\nconst { serialize, deserialize } = require(`./utils.js`);\nmodule.exports.serialize = serialize;\nmodule.exports.deserialize = deserialize;' pkg/nodejs/ezkl.js | |
- name: Expose serialize and deserialize imports in web target | |
run: | | |
sed -i '51i\ | |
// import serialize and deserialize from utils.js\ | |
import { serialize, deserialize } from '\''./utils.js'\'';\ | |
export { serialize, deserialize };' pkg/web/ezkl.js | |
- name: Add serialize and deserialize imports to nodejs ezkl.d.ts | |
run: | | |
sed -i '1i\ | |
export declare function serialize(data: object | string): Uint8ClampedArray;\ | |
export declare function deserialize(buffer: Uint8ClampedArray | Uint8Array): any;' pkg/nodejs/ezkl.d.ts | |
- name: Add serialize and deserialize imports to web ezkl.d.ts | |
run: | | |
sed -i '1i\ | |
export declare function serialize(data: object | string): Uint8ClampedArray;\ | |
export declare function deserialize(buffer: Uint8ClampedArray | Uint8Array): any;' pkg/web/ezkl.d.ts | |
- name: Create README.md in pkg folder | |
run: | | |
curl -s "https://raw.githubusercontent.com/zkonduit/ezkljs-engine/main/README.md" > ./pkg/README.md | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: "18.12.1" | |
registry-url: "https://registry.npmjs.org" | |
- name: Publish to npm | |
run: | | |
cd pkg | |
npm install | |
npm ci | |
npm publish | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
in-browser-evm-ver-publish: | |
name: publish-in-browser-evm-verifier-package | |
needs: [publish-wasm-bindings] | |
runs-on: ubuntu-latest | |
if: startsWith(github.ref, 'refs/tags/') | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Update version in package.json | |
shell: bash | |
env: | |
RELEASE_TAG: ${{ github.ref_name }} | |
run: | | |
sed -i "s|\"version\": \".*\"|\"version\": \"${{ github.ref_name }}\"|" in-browser-evm-verifier/package.json | |
- name: Prepare tag and fetch package integrity | |
run: | | |
CLEANED_TAG=${{ github.ref_name }} # Get the tag from ref_name | |
CLEANED_TAG="${CLEANED_TAG#v}" # Remove leading 'v' | |
echo "CLEANED_TAG=${CLEANED_TAG}" >> $GITHUB_ENV # Set it as an environment variable for later steps | |
ENGINE_INTEGRITY=$(npm view @ezkljs/engine@$CLEANED_TAG dist.integrity) | |
echo "ENGINE_INTEGRITY=$ENGINE_INTEGRITY" >> $GITHUB_ENV | |
- name: Update @ezkljs/engine version in package.json | |
shell: bash | |
env: | |
RELEASE_TAG: ${{ github.ref_name }} | |
run: | | |
sed -i "s|\"@ezkljs/engine\": \".*\"|\"@ezkljs/engine\": \"$CLEANED_TAG\"|" in-browser-evm-verifier/package.json | |
- name: Update the engine import in in-browser-evm-verifier to use @ezkljs/engine package instead of the local one; | |
run: | | |
sed -i "s|import { encodeVerifierCalldata } from '../nodejs/ezkl';|import { encodeVerifierCalldata } from '@ezkljs/engine';|" in-browser-evm-verifier/src/index.ts | |
- name: Update pnpm-lock.yaml versions and integrity | |
run: | | |
awk -v integrity="$ENGINE_INTEGRITY" -v tag="$CLEANED_TAG" ' | |
NR==30{$0=" specifier: \"" tag "\""} | |
NR==31{$0=" version: \"" tag "\""} | |
NR==400{$0=" /@ezkljs/engine@" tag ":"} | |
NR==401{$0=" resolution: {integrity: \"" integrity "\"}"} 1' in-browser-evm-verifier/pnpm-lock.yaml > temp.yaml && mv temp.yaml in-browser-evm-verifier/pnpm-lock.yaml | |
- name: Use pnpm 8 | |
uses: pnpm/action-setup@v2 | |
with: | |
version: 8 | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: "18.12.1" | |
registry-url: "https://registry.npmjs.org" | |
- name: Publish to npm | |
run: | | |
cd in-browser-evm-verifier | |
pnpm install --frozen-lockfile | |
pnpm run build | |
pnpm publish --no-git-checks | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |