The JS build now runs end to end and the built package has been consumed the way
quantus/common will consume it. Four things had to be worked out.
polkadot-dev-build-ts will not build this package. It returns early for any name
not starting with @polkadot/, in both buildJs and when collecting locals for
import rewriting. Renaming into someone else's scope to satisfy a string check
would be worse than not using the tool, and nothing is lost: this package needs
no deno variant, no rollup bundle, no cross-package import rewriting. A plain tsc
build lives in scripts/build-quantus-js.sh, which also keeps `yarn build:js`
byte-identical to upstream's behaviour.
binaryen 105 silently breaks the wasm. Upstream pins version_105 (2021), which
predates the externref tables wasm-bindgen 0.2.128 emits; wasm-opt "optimises"
the table into something that fails at instantiation with `WebAssembly.Table.
grow(): failed to grow table by 4`. The wasm is valid before wasm-opt and broken
after, every cargo test still passes, and it only surfaces when a consumer tries
to init. install-build-deps.sh now fetches binaryen 123 alongside, exactly as it
does a second wasm-bindgen.
The wasm-util dependency is imported deeply. Its package index re-exports
packageDetect, whose only job is a side effect registering with @polkadot/util —
a peer dependency we would inherit for nothing. base64 and fflate are pure
functions with no dependencies, so the deep paths are both lighter and honest.
ESM only, and the CJS scaffolding is removed. The consumers are ESM and the
wasm-bindgen glue is ESM-only, so a CJS variant would mean a second generated
glue or hand-written marshalling. Revisit if quantus/common's CJS build needs it.
Also: the pack step must run after tsc, which clears build/; the checked-in
bindings are refreshed by the build so they cannot drift; and both test suites
are wired into the repo's test script, which previously ran wasm-crypto's only.
The consumer test stages a real node_modules layout rather than testing in place,
because in this repo node_modules/@polkadot/wasm-util symlinks to the package
source, which carries no exports map — so a deep import resolves for a real
consumer and fails here for reasons that have nothing to do with our package.
Staging tests module resolution too, which is half of what can break in a
published package. It is also what caught the binaryen fault.
Post-wasm-opt: 234,292 raw / 109,649 zlib / 146,200 base64 — smaller than
upstream's entire wasm-crypto blob (335,277 / 168,782 / 225,044).
Refs quantus/wasm#1
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012uDUodEcRbBwNRi3UCmw8f
Wraps the crate for JS consumers and adds the build that produces it.
Init deliberately avoids fetch and avoids @polkadot/wasm-bridge. The consumer is
an MV3 service worker under `script-src 'self' 'wasm-unsafe-eval'`, which can
compile WASM but not usefully fetch it, and which can be cold-started between any
two messages; callers like pair.sign() are synchronous and have no await to give.
So the WASM is zlib-compressed and base64'd into bytes.js at build time and
instantiated with wasm-bindgen's initSync. Bridge is not usable here regardless:
it implements the 0.2.79 JS-heap ABI and this crate builds with 0.2.128, which
uses externref tables.
build-quantus.sh is separate from build-wasm.sh rather than folded into it,
because that script drives the nightly-2022-06-24 + xargo build wasm-crypto
needs. install-build-deps.sh gains a second wasm-bindgen for the same reason —
the two ABIs cannot share a binary. No asm.js step: wasm2js over ML-DSA would be
enormous and slow, and every context we ship into permits wasm.
bytes.js is emitted in both module systems, with the CJS copy under a directory
carrying its own {"type":"commonjs"} — the package is "type": "module" and node
otherwise refuses to load an exports.-style file from it.
Proven end to end against the real build output: base64 -> inflate -> initSync
with no fetch, crystal_alice's account id matching the CLI through the JS path,
sig||pk matching the runtime's fixed-array size, and JsError surfacing as a JS
exception across the boundary.
Sizes are read from the crate rather than exposed as constants to copy. They are
consensus-critical and a drifted JS constant would re-frame every byte after the
signature while looking entirely healthy.
Refs quantus/wasm#1
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012uDUodEcRbBwNRi3UCmw8f
* chore: revert asm build
* chore: revert info in build-wasm.sh
* chore: revert install-build-deps.sh
* chore: lock libc version
* chore: lock libc version in xargo
* chore: use --locked while building
* Fix: Switch `RUST_VER` to 1.63.0-nightly
* chore(CI): revert continue-on-error to false
* Revert "chore(CI): revert continue-on-error to false"
This reverts commit 425a93ea4d6c18e94ca04a0142818dd440442182.
---------
Co-authored-by: Francisco Valentim Castilho <franciscoannyon@gmail.com>
* run CI
* run CI
* setup nightly as default
* install nightly-2024-11-22
* rustup show
---------
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
* get rust versions
* modify build-wasm
* switch to nightly on build-wasm
* prevent script from using stable
* extra log
* new log
* run CI on current branch
* run CI on current branch
* Minor fixes
* Remove rust installation
* nightly on build.sh
* add log
* logs
* small change
* rust version is nightly
* auto-approve
* re add lock file
---------
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
* get rust versions
* modify build-wasm
* switch to nightly on build-wasm
* prevent script from using stable
* extra log
* new log
* run CI on current branch
* run CI on current branch
* Minor fixes
* Remove rust installation
* nightly on build.sh
* add log
* logs
* small change
* rust version is nightly
* auto-approve
---------
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
* chore: added validation checks in PBKDF2 and Scrypt functions
* chore(eslint): ignore linting for mod.ts
* chore(ci): bump RUST_VER
* chore(ci): bump RUST_VER
* chore(CI): downgrade RUST_VER and update xargo build script
* chore(CI): revert last change and use RUST_VER as stable
* chore(CI): bump BINDGEN_VER
* chore(CI): bump BINDGEN_VER
* chore(CI): bump BINARYEN_VER
* chore(CI): downgrade BINARYEN_VER
* chore(CI): recomended fix for wasm-bindgen
* chore(test): point wasm to package
* Revert "chore(test): point wasm to package"
This reverts commit 66104540fdff0e760ca0a6a666d4e09d162c5769.
* chore(test): temporary test
* Revert "chore(test): temporary test"
This reverts commit af10b8d8b9bb597e02ea9c8d6cc3bf62676a6609.
* chore(test): added more logs to build-wasm.sh script
* Revert "chore(test): added more logs to build-wasm.sh script"
This reverts commit c5073005ae9daa84308296736a41636da8f3d21b.
* chore(test): added more logs to test all
* Revert "chore(test): added more logs to test all"
This reverts commit 9b0ac43c2c053ac408164bbf9b31b46d0844af1b.
* chore: add references for RFCs