Commit Graph
89 Commits
Author SHA1 Message Date
grenadeandClaude Opus 5 3a1611a92e feat: add @quantus/codec, driving encode and decode from runtime metadata
The extension has to build a signing payload, assemble an extrinsic and decode
a call well enough to show a user what they are approving. The obvious route was
@polkadot/api's codec. That is closed, and quantus/api#1 carries the tested
evidence:

  - @polkadot/types caps fixed arrays at 2048 bytes, and ML-DSA signatures are
    [u8;5261] and [u8;7219], so every Quantus extrinsic trips it
  - api.rpc.chain.getBlock throws on every block of this chain, at the timestamp
    inherent, because it reads the extrinsic preamble byte as a version when the
    top two bits are a type tag
  - it *guesses* that signed extensions it does not recognise contribute nothing
    to the signed payload

The third is why this is a package rather than a patch. The guess is right
today — the registry says ReversibleTransactionExtension and
WormholeProofRecorderExtension are empty on both halves — and it is right only
by luck. This chain's encoding has changed between runtimes, transactionVersion
has gone 2 -> 3 -> 6 across four upgrades, and when the guess stops holding the
wallet keeps signing: valid signatures over a payload missing bytes the runtime
put there, reported by the chain as BadProof, which is also what it reports for
a wrong key.

So nothing here names a pallet, a call, an extension or a signature scheme.
Every type id is read from metadata the node produced by running
Metadata_metadata against the runtime WASM in a given block's state, the same
oracle blackbeard.observer has been decoding against across four upgrade
boundaries. encode_extensions walks the declared extensions in order and refuses
to build a payload when one that encodes to something has no value supplied —
a wallet that cannot sign is a bug report, one that signs the wrong bytes is a
support case nobody diagnoses.

Proven end to end on Heisenberg at spec 148: a balances.transfer_keep_alive
built entirely here, signed by @quantus/crypto under QUANTUS_EXTRINSIC, included
at block 1050475 and read back from that block — inherent at index 0 included,
which is the block @polkadot/api cannot decode at all.

Two notes carried over from @quantus/crypto, both load-bearing: decode_checked
walks with scale_decode's IgnoreVisitor before scale_value touches the bytes,
because scale_value sizes a Vec from the length prefix before decoding an item
and an aborted allocation leaves no Err to catch; and the build needs binaryen
123, since 105 silently corrupts the output.

Closes #3

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012uDUodEcRbBwNRi3UCmw8f
2026-09-15 14:14:34 +03:00
rob thijssenandClaude Opus 5 e8bf9e20c7 fix(quantus-crypto): strip wasm-bindgen's fetch-based init from the shipped glue
The package could not be bundled. Every webpack consumer failed with:

  Module not found: Error: Can't resolve 'quantus_crypto_bg.wasm'
    in node_modules/@quantus/crypto/generated

wasm-bindgen's async `__wbg_init` contains

  module_or_path = new URL('quantus_crypto_bg.wasm', import.meta.url);

and webpack resolves `new URL(..., import.meta.url)` statically, at build time,
whether or not the branch can run. The file is not in the package — the wasm
ships base64'd in bytes.js, which is the entire point of this package — so the
build failed on a code path we never call.

node never sees it, which is why ten Rust tests, twelve consumer assertions and a
browser probe all passed while the package was unusable in a bundler. It took a
real extension build to surface, and that is the useful lesson: this package's
consumers bundle, and nothing in its own test suite does.

So the dead init is removed after bindgen runs. Shipping a second copy of the
wasm to satisfy a path we do not use would be the wide fix; deleting generated
code we never call is the narrow one.

The stripper asserts the shape it expects and throws if wasm-bindgen changes it,
rather than silently no-opping — a build that quietly stopped stripping would
ship the broken package again. It also re-checks that no reference to the .wasm
filename survives.

Published as 0.1.1.

Refs quantus/wasm#1, quantus/extension#2

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012uDUodEcRbBwNRi3UCmw8f
2026-09-15 11:53:18 +03:00
rob thijssenandClaude Opus 5 a6d3685c59 refactor(quantus-crypto): drop the @polkadot/wasm-util dependency
It cost more than it saved. Two problems, the second only visible once
quantus/common tried to consume this package:

Its index re-exports packageDetect, whose only job is a side effect registering
with @polkadot/util — a peer dependency inherited for nothing. Deep imports
(/base64, /fflate) avoided that.

But it is a workspace package, so a symlinked consumer resolves its dependencies
through *this* repo's node_modules, where @polkadot/wasm-util points at the
package source rather than its build and carries no exports map. Node follows
symlinks to their realpath, so `@polkadot/wasm-util/base64` failed to resolve
from quantus/common no matter which yarn protocol was used — portal: and link:
behave the same once the realpath is taken.

So: fflate directly for zlib inflate, and fifteen lines for base64 rather than a
dependency at all. Deliberately not atob or Buffer.from — the first is
browser-only, the second node-only, and this runs in an MV3 service worker, a
Worker, node tests and a bundled extension page.

The package is now self-contained apart from fflate, which resolves normally from
any checkout. Size is unchanged at 234,292 raw / 109,649 zlib / 146,200 base64.

Refs quantus/wasm#1, quantus/common#2

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012uDUodEcRbBwNRi3UCmw8f
2026-09-10 18:39:54 +03:00
rob thijssenandClaude Opus 5 b882f914e7 build(quantus-crypto): buildable, installable and tested as a package
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
2026-09-10 14:17:15 +03:00
rob thijssenandClaude Opus 5 1f1f5729ab feat(quantus-crypto): JS surface, build scripts and CSP-safe sync init
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
2026-09-10 13:58:25 +03:00
Tarik Gul 65286fb3ec Set headers to 2026 (#609)
Lock Threads / lock (push) Has been cancelled
2026-03-13 01:32:10 +02:00
rajk93andFrancisco Valentim Castilho 278ecc7210 Fix/Revert asm build (#599)
* 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>
2025-11-10 18:31:44 +05:30
Valentin Fernandezandgithub-actions[bot] d7a1060824 Remove ASM build (#594)
* Remove ASM build

* remove CI build blag

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2025-08-13 13:59:40 -03:00
c6f8748878 Tweak install-build-deps.sh script (#593)
* add additional flag

* downgrade bindgen

* Fix rust build

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: José Molina <jose@blockdeep.io>
2025-08-13 13:34:01 -03:00
Valentin Fernandezandgithub-actions[bot] 24a46c7262 Setup nightly as default (#592)
* 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>
2025-08-13 17:01:17 +03:00
Valentin Fernandezandgithub-actions[bot] 78a282bda3 Readd lock file (#591)
* 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>
2025-08-12 12:02:48 -03:00
Valentin Fernandezandgithub-actions[bot] 1713dccba3 Ci Fix (#590)
* 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>
2025-08-12 11:40:51 -03:00
Valentin Fernandezandgithub-actions[bot] 0a22251212 default to nightly build (#589)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2025-08-12 09:56:45 -03:00
Valentin Fernandezandgithub-actions[bot] 540d46717b default to installed rust version (#588)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2025-08-11 13:33:46 -03:00
Valentin Fernandezandgithub-actions[bot] e5112e690d fix rust version to 1.84 (#587)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2025-08-11 12:01:58 -03:00
Valentin Fernandezandgithub-actions[bot] 2f8c91fc15 rollback bindgen version change (#586)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2025-08-11 11:41:17 -03:00
rajk93 6d552f1ced Added validation checks in PBKDF2 and Scrypt hashing functions (#584)
* 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
2025-07-23 12:10:03 +05:30
github-actions[bot] 042d653852 [CI Skip] bump/beta 7.4.2-1-x
skip-checks: true
2025-01-02 19:57:35 +00:00
Tarik Gul 6777f8ef5e 2025 (#574)
* 2025

* include more files
2025-01-02 17:31:20 +02:00
Jaco 8352373fdd 2024 (#559) 2024-01-08 15:07:04 +02:00
Jaco 7611fd1788 Collapse build:mac command into build (w/ detect) (#541) 2023-08-31 15:44:26 +03:00
Jaco 319f33bec1 Bump dev (#534)
* Bump dev

* Adjust linting
2023-08-16 11:14:44 +03:00
Jaco 4565f85077 CJS export cleanups (#523) 2023-05-16 09:31:41 +03:00
Jaco b7768c369c cjs/bytes.js generation adjustment (#520) 2023-05-08 16:36:00 +03:00
Jaco cbb7cd94f7 Add repo dev req. for Node.js (#508) 2023-03-25 17:46:17 +02:00
Jaco 3b286e6034 Use tsc compiler (#486) 2023-03-04 13:57:24 +02:00
Jaco aeae6c137e Swap TS -> JS compiler to use swc (#485) 2023-03-03 14:02:01 +02:00
Jaco f3a5b7e373 Convert pack wasm to ESM (#463)
* Convert pack wasm to ESM

* Cleanup clean scripts

* Adjust
2023-01-27 10:26:14 +02:00
Jaco f4080e5754 Update headers for 2023 (#454) 2023-01-01 10:23:06 +02:00
Jaco b1350bd8b4 Adjust size stats output on build (#393) 2022-07-08 10:41:42 +03:00
Jaco f31ec881ef Additional platform-specific tests (#387)
* Additional platform-specific tests

* align casing

* Step rename

* lenIn/lenOut for deno

* Remove install ls

* Run deno tests on full suite

* trigger
2022-07-06 12:46:38 +03:00
Jaco f4db1385fc Bump dev (w/ stable deno publish) (#367) 2022-06-21 15:43:49 +03:00
Jaco 04285faf55 Adjust wasm build process w/ wasm-crypto naming (#343) 2022-05-11 12:54:36 +03:00
Jaco e75ebd07a0 Restore older package names (#342)
* Restore older package names

* Fix headers

* Adjust imports & tupe exports
2022-05-11 09:01:12 +03:00
Jaco 2e14af5693 Adjust WASM init process (w/ RN aliases) (#340)
* Adjust WASM init process (w/ RN aliases)

* Remove stray log

* Cleanup

* CHANGELOG

* yarn.lock
2022-05-09 17:48:45 +03:00
Jaco 0dfb491e9d Reproduction for secp256k1 asm.js failure (#310)
* Reproduction for secp256k1 asm.js failure

* Make test output more readable

* Additional test cleanups

* Bump build deps

* Adjust output sizing flags

* Bump wasm-bindgen

* secp256k1 HACK

* Update packages/wasm-crypto/src/bundle.ts

* Update packages/wasm-crypto/src/bundle.ts

* Update packages/wasm-crypto/test/all/index.cjs
2022-03-19 09:02:52 +02:00
Jaco be4f3ce82c 2022 (#263)
* 2022

* Update scripts/rust-version.sh
2022-01-01 09:30:22 +02:00
Jaco 39deef5b8b tsconfig project references (#249)
* Use tsconfig references

* Working :)

* Ignore bytes outputs

* spacing

* Adjust

* tsconfig.eslint.json

* Upgrade

* Include scripts in linting
2021-12-14 07:54:31 +02:00
Jaco 7689afb616 Add secp256k1 interfaces (#241)
* Add secp256k1 functions

* features for rand

* JS tests

* signing

* CHANGELOG

* Add secp256k1 seed
2021-12-02 14:19:33 +02:00
Jaco d5512418d2 Use stable as nightly compiler (#192)
* Use stable as nightly compiler

* detect stable

* Apply suggestions from code review

* CHANGELOG

* De-dupe Rust version

* Adjust script location

* Script cleanups

* trigger

* Script location
2021-08-25 11:55:17 +02:00
Jaco cf20e027af Single module bundle via rollup (#203)
* Single module bundle via rollup

* Adjust naming

* Allow multiple bundles (consistency)

* Remove unused rollup plugins

* Update rollup.config.js

* preferConst

* Rollup with dev build

* Use createBundle

* Update rollup.config.mjs

* Add bundle entrypoint

* Bump dev

* Bump dev

* Remove x-* overrides
2021-07-07 17:34:32 +02:00
Jaco Greeff 25d9e21b38 Adjust esm -> cjs imports (4.0.2) (#185)
* Adjust esm -> cjs impors

* cleanups

* CHANGELOG

* Apply suggestions from code review

* Apply suggestions from code review

* Apply suggestions from code review

* Update packages/wasm-crypto-wasm/src/empty.ts

* Apply suggestions from code review

* Update packages/wasm-crypto-wasm/src/cjs/bytes.d.ts
2021-03-05 22:55:19 +01:00
Jaco Greeff 641ea0f9d8 Small cleanups (#182)
* Small cleanups

* Detect wasm-crypt-* alongside detectPackage

* Adjust alias imports

* Adjust

* Adjust
2021-03-04 17:59:38 +01:00
Jaco Greeff 0f6e143a6f Default build to type: module (#180)
* Defaul build to type: module

* Add packageInfo

* 4.0

* pre

* Adjust tests

* jest js, rest cjs

* Bump dev
2021-03-02 17:27:41 +01:00
Jaco Greeff 63622edcf4 Cleanup implicit dependencies, perform base64 decoding using base64-js (#178)
* Cleanup implicit dependencies, perform base64 decoding using base64-js

* base64 decoding

* lint

* remove extra call

* adjust
2021-02-24 17:09:06 +01:00
Jaco Greeff 8510120701 Bumps (#173)
* Bumps

* Update fflate imports
2021-01-21 12:59:06 +01:00
Jaco Greeff 1bb6db86f7 2021 (#167) 2021-01-03 11:20:26 +01:00
Jaco Greeff 3c13f266df Bundle unzlibSync (no worker requirement, stop-gap) (#162)
* Bundle unzlibSync (no worker requirement, stop-gap)

* Bump deps

* Pass uncompressedSize

* mjs fixes
2020-12-19 11:24:59 +01:00
Jaco Greeff 2c4f8bbe4e 3.0 (#158)
* 3.0

* CHANGELOG

* Rename content packages

* final dev bump
2020-12-13 10:09:24 +01:00
Jaco Greeff 8837ec9386 Use lz4 on the WASM stream (#159)
* Use lz4 on the WASM stream

* Allow fflate tree-shaking

* Rewrite deps
2020-12-12 13:09:47 +01:00