Skip to content

fix(wasm): secp256k1 did:key in the WASM build (LC-2431) - #21

Merged
TaylorBeeston merged 1 commit into
mainfrom
fix/lc-2431-secp256k1-did-key
Nov 17, 2026
Merged

TaylorBeeston merged 1 commit into
mainfrom
fix/lc-2431-secp256k1-did-key

Conversation

@TaylorBeeston

@TaylorBeeston TaylorBeeston commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Jira: LC-2431

keyToDID('key', <secp256k1 JWK>) fails in the WASM with Unable to generate DID, and did:key:zQ3s… DIDs don't resolve either. didkit-wasm builds didkit with default-features = false and never turned secp256k1 back on, so did-method-key was compiled without it. did:ethr and did:pkh kept working because they don't go through did-method-key.

This adds secp256k1 to didkit-wasm's didkit features. That's the whole fix.

Also in here:

  • A Rust test that goes seed bytes → generateSecp256k1KeyFromBytes → keyToDID('key') → resolveDID, then checks the resolved key matches. It fails on main with UnableToGenerateDID.
  • CI's WASM test step now runs every didkit-wasm lib test (cargo test -p didkit-wasm --lib). Before, it only ran jwe::tests, so the new test wouldn't have run.
  • A "DID methods" section in lib/web/README.md that lists what the WASM can generate and resolve, and says plainly that did:ion and did:onion don't resolve there. Both read their endpoint from an env var, and a browser has none. The LearnCard docs that advertised did:ion are fixed in docs: stop listing did:ion as resolvable (LC-2431) LearnCard#2066.

Size

Basically nothing, which makes sense since k256 is already linked in for did:ethr (wasm-pack 0.13.1 + wasm-opt -Oz from Binaryen 124, rustc 1.98.0, same flags as LearnCard's build script):

raw brotli-11
main (82ef1d9) 4,613,964 1,230,744
this PR 4,613,504 1,231,493
Δ −460 +749

Testing

  • cargo test --locked -p didkit-wasm --lib: 4 passed, including the new test. With the Cargo.toml change reverted, the new test fails with UnableToGenerateDID.
  • I built the WASM and ran Probe's repro plus a DID-method check in Node. secp256k1 keyToDID('key'), keyToVerificationMethod('key') and resolveDID all work. An EcdsaSecp256k1Signature2019 VC issued by a secp256k1 did:key verifies with no errors. Every method the README lists as working generated and resolved, and did:ion/did:onion failed the way the README says.
  • LearnCard's @learncard/didkit-plugin vitest against this build: 40/40, the same as the shipped WASM.

To try it: wasm-pack build lib/web --target web --locked, then in Node call keyToDID('key', generateSecp256k1KeyFromBytes(new Uint8Array(32).fill(7))). You should get a did:key:zQ3s….

LearnCard follow-up

LearnCard doesn't need a code change for this. Its own did:key comes from the Ed25519 key, so nothing in the app changes. SDK callers who pass a secp256k1 key to keyToDid('key', …) get a DID instead of an error. LearnCard picks it up when lib/didkit is bumped and the WASM rebuilt, which the notify-learncard workflow kicks off on merge.

— Grok Bot

didkit-wasm built didkit without the secp256k1 feature, so did-method-key
had no secp256k1 support: keyToDID('key', <secp256k1 JWK>) failed with
'Unable to generate DID' and did:key:zQ3s... DIDs didn't resolve.

Adds a round-trip test (seed bytes -> JWK -> did:key -> resolved key),
runs every didkit-wasm lib test in CI instead of only the JWE ones, and
documents which DID methods work in the WASM build (did:ion and did:onion
don't).

@Custard7 Custard7 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at 7fee038. No blocking issue found. The added feature correctly propagates through didkit/secp256k1 to did-method-key's gated generation and resolution paths, and the round-trip assertion checks both public coordinates rather than only a DID prefix. Current-head CI is green, including the expanded WASM library test step and WASM package build.

Nonblocking follow-up: automate the reported Node/WASM exported-API round trip (and signature issue/verify) in CI. The new cargo test runs natively, while lib/Makefile's WASM package target builds but explicitly runs no test, so those two checks do not independently exercise the generated JS/WASM boundary. I reviewed source and hosted CI status; I did not rerun a local Rust/WASM build or independently reproduce the size figures.

@TaylorBeeston
TaylorBeeston merged commit 35d0889 into main Nov 17, 2026
7 checks passed
@TaylorBeeston
TaylorBeeston deleted the fix/lc-2431-secp256k1-did-key branch November 17, 2026 04:57
TaylorBeeston added a commit that referenced this pull request Nov 17, 2026
Custard7 asked for the capability changes to live in the package docs, not
just the PR body. lib/web/README.md gets a section listing the dropped zcap
exports and the dropped did:webkey/did:onion/did:ion methods, and how to get
each back. The DID methods section from #21 now says those three return
methodNotSupported instead of describing their old browser failures.
CHANGELOG.md gets matching Unreleased entries.
TaylorBeeston added a commit that referenced this pull request Nov 17, 2026
* perf(wasm): codegen-units=1 and make the zcap exports opt-in (LC-2429)

Two no-risk size cuts:

- codegen-units = 1 in the workspace release profile. LLVM sees the whole
  crate graph in one unit, so it inlines and dedupes more.
- didkit-wasm default features drop invoke and delegate. Those gate the 9
  zcap exports (delegateCapability, invokeCapability, verifyDelegation...),
  which LearnCard never calls. Build with --features invoke,delegate to
  get them back. The imports and helpers only those exports use are now
  gated too, so every feature combination still builds with -Dwarnings.

* perf(wasm): leave did:webkey, did:onion and did:ion out of the WASM build (LC-2429)

The three methods become default features of the didkit crate, so the CLI,
HTTP server and C/Java bindings keep them. didkit-wasm already depends on
didkit with default-features = false, so it drops them.

None of them works in the browser today:
- did:ion reads DID_ION_API_URL from the environment, which a browser
  doesn't have, so every resolve fails with 'Missing Sidetree API endpoint'.
- did:onion sends plain HTTP to the .onion host with no Tor proxy.
- did:webkey has no callers in LearnCard and is the only reason the OpenPGP
  stack (pgp, dsa, sha1-checked) is linked in.

pgp was also the only crate turning on x25519-dalek's static_secrets
feature, which jwe.rs needs, so didkit-wasm now asks for it directly.

* perf(wasm): leave the schema.org and traceability contexts out (LC-2429)

TAYLOR'S CALL. Turns on ssi-json-ld's omit-large-contexts for the WASM
build only. The static loader stops embedding https://schema.org/ (~200 KB)
and https://w3id.org/traceability/v1 (~123 KB).

What breaks: a document whose @context includes either IRI no longer
resolves from the built-in loader. It resolves if the caller puts the
context in the context map (LearnCard's getDocumentMap does this when its
context plugin can resolve the IRI, e.g. with remote contexts allowed);
otherwise expansion fails with 'Unknown context'. No LearnCard-issued
credential uses either context.

Needs learningeconomy/ssi 0c5405a (omit-large-contexts), so CI's SSI_REF
moves to it.

* perf(wasm): skip JSON Schema validation in the WASM build (LC-2429)

TAYLOR'S CALL. Turns on ssi-vc's omit-json-schema for the WASM build only.
boon and the regex engine behind it (~925 KB raw) stop being linked in.

What breaks: verifyCredential with checks: ['credentialSchema'] no longer
validates the credential against its 1EdTechJsonSchemaValidator2019
schema. It returns a warning ('credentialSchema not checked: ...') and
leaves credentialSchema out of checks. Proofs, status and expiry are
unaffected. LearnCard's vc plugin adds that check whenever a credential has
a credentialSchema (OBv3/CLR), so callers that need the check would have
to validate in JS (e.g. ajv) or on a server.

Needs learningeconomy/ssi 79b56b3 (omit-json-schema), so CI's SSI_REF
moves to it.

* ci: point the Docker build at the same ssi ref as build.yml (LC-2429)

* revert: keep JSON Schema validation in the WASM build (LC-2429)

Reverts 95f3369. omit-json-schema made verifyCredential return errors: []
for a signed, schema-invalid credential when the caller asked for the
credentialSchema check. Taylor's call is to keep the check.

This reverts commit 95f3369.

* revert: keep the schema.org and traceability contexts in the WASM (LC-2429)

Reverts 9d6fc98. Taylor's call is to keep both contexts in the built-in
loader. With (c) and (d) gone, didkit-wasm no longer needs any ssi feature
from learningeconomy/ssi#17, so build.yml's SSI_REF goes back to main's.

This reverts commit 9d6fc98.

* revert: point the Docker build back at main's ssi ref (LC-2429)

Reverts feb932d. It only moved push_image.yml to the ssi#17 head so it
matched build.yml. Nothing here needs that ref now, so both workflows go
back to 9e2783f, same as main.

This reverts commit feb932d.

* docs(wasm): document what the default WASM build leaves out (LC-2429)

Custard7 asked for the capability changes to live in the package docs, not
just the PR body. lib/web/README.md gets a section listing the dropped zcap
exports and the dropped did:webkey/did:onion/did:ion methods, and how to get
each back. The DID methods section from #21 now says those three return
methodNotSupported instead of describing their old browser failures.
CHANGELOG.md gets matching Unreleased entries.

TaylorBeeston commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator Author

Acceptance Loom for LC-2431 (docs half on camera; WASM half cited via this PR’s regression test):
https://www.loom.com/share/f91e9c4f599d42db8e87a8c569a00769

Docs: did:ion marked unsupported. Console/WASM demo not filmed.

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.

2 participants