Repository navigation
Release 2.4.0 - #1
Merged
Merged
Conversation
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.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
DPoPNonceStoreTest plan