Skip to content

Release 2.4.0 - #1

Merged
CtrlAltDevelop merged 7 commits into
mainfrom
develop
Nov 29, 2026
Merged

CtrlAltDevelop merged 7 commits into
mainfrom
develop

Conversation

@CtrlAltDevelop

Copy link
Copy Markdown
Owner

Summary

  • perf: multiply the generator with a Jacobian comb, ~11x faster proofs
  • feat: remember server nonces per origin with DPoPNonceStore
  • feat: store and restore a key as a JWK
  • feat: publish a live demo to GitHub Pages
  • docs: relicense under AGPL-3.0; release 2.4.0
  • ci: run tests on pull requests to main only, via shared ci-workflows

Test plan

  • CI passes on this PR
  • Verify the 2.4.0 version/changelog entries

Tests-only gate (dart-test.yml) on pull requests into main; nothing runs on
any other branch or event. Publishing uses the shared dart-publish.yml.
The badge and the README footer that name the licence land with the
2.4.0 documentation, since that file carries unrelated changes too.
A proof costs one ES256 signature, and an ES256 signature costs one
scalar multiplication of the generator. pointycastle holds curve points
in affine coordinates, so every addition and doubling divides — one
modular inverse each, the most expensive operation in the field, some
340 of them for a single k * G.

Two changes, neither of which alters a signature. The multiplication
now runs in Jacobian coordinates, deferring the division to a single
inverse at the end; and because the generator never changes, its
multiples are precomputed into a Lim-Lee comb of eight blocks, so k * G
costs 32 doublings and 32 additions rather than 256 and 64. On the Dart
VM a proof goes from ~2.8 ms to ~0.23 ms. Key generation and
fromPrivateKeyPem multiply too, and get the same.

The 255-entry table costs about 15 ms once, on the first signature, and
roughly 35 KB for the life of the process — so a process that signs a
single proof and exits is slower than it was. Its entries are converted
to affine form a layer at a time with Montgomery's trick, nine inverses
rather than 255, which is what keeps that build from costing more than
the first forty signatures.

ECDSASigner still derives k (RFC 6979) and computes r and s: the only
borrowed work is the multiplication. Signatures are byte-for-byte what
they were, and the tests check the comb against pointycastle's own
arithmetic for 250 random scalars, for every single-bit scalar in all
256 positions, at the row boundaries and on the curve equation.

The P-256 domain parameters are also built once per process instead of
per call, since ECCurve_prime256v1() decompresses the generator each
time it is constructed and isP256 alone was paying for that twice per
key.
A server that wants a nonce answers 401 with error="use_dpop_nonce" and
a DPoP-Nonce header, and may issue another on any later response. Doing
that by hand means holding a nonce per server, reading the header off
every response and retrying exactly once — the snippet the README used
to recommend.

DPoPNonceStore holds that state, keyed by origin, which is the
granularity RFC 9449 §8.2 gives it: an authorization server and a
resource server run separate nonce spaces. Hand one to DPoPClient or
DPoPSignerClient and every proof carries the right nonce without the
call site passing it; an explicit nonce: still wins.

update(url, headers) returns true only for a nonce the store had not
already tried, which is both the reason to retry and the guard against
retrying forever. Header names are matched case-insensitively, since a
map assembled by a gateway SDK may not be lower-cased. forget(url)
drops one origin, clear() the lot.

Memory only, and no HTTP client: a nonce is short-lived and
server-issued, so losing the lot on restart costs one round trip.
The package could only persist a key as a PEM, which is awkward for
storage that holds JSON and for anything interoperating with WebCrypto
or a JOSE library in another language.

privateJwk is the public jwk plus d, the form RFC 7518 §6.2.2 gives an
EC private key, so the two storage shapes are the same key and sign
byte-identical proofs. fromPrivateJwk reads only kty, crv, d, x and y,
so a crypto.subtle.exportKey('jwk', ...) result can be passed through
with its ext and key_ops still on it.

x and y are optional, since the public half is derived from d, and
checked when present: a JWK whose coordinates do not belong to its d is
refused rather than used to publish a key that cannot verify its own
signatures, which is the guard fromPem already had. A JWK that is not a
readable P-256 private key throws a FormatException, as the PEM
constructors do.

privateJwk carries the private key, so it belongs in the keystore with
privateKeyPem; dpopThumbprint still refuses anything carrying d.
example/web is the package compiled with dart compile js: generate a
key or paste your own, as a PEM or a JWK, sign a proof for a request
you describe, and read the claims a server would check. Nothing is
mocked and no key or token leaves the browser.

Only the crypto is Dart — the page does its own DOM work in plain
JavaScript, so the demo needs no web framework and the Dart file stays
down to the calls worth demonstrating. main.dart.js is built, not
committed.

The workflow is local rather than shared from ci-workflows the way the
Flutter one is: this is a pure Dart package, so the build is
dart compile js rather than flutter build web, and it is three lines.
Settings > Pages > Source has to be set to "GitHub Actions" before the
first deploy.

The command-line example picks up the nonce store and the JWK
round-trip alongside it.
The nonce store, JWK key storage and the faster signing, with the
README gaining a Speed section that gives the numbers and says plainly
which case got slower: a process that signs one proof and exits now
pays ~15 ms to build the comb table.

The licence badge and footer settle here too, with the relicensing
commit that could not carry them.
@CtrlAltDevelop CtrlAltDevelop self-assigned this Nov 29, 2026
@CtrlAltDevelop
CtrlAltDevelop merged commit 5a6007a into main Nov 29, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant