fix(passkey): typed PasskeyError everywhere + shared predicate adoption - #43
Merged
Conversation
…w factories Two coupled cleanups to align passkey error handling with the rest of the repo: 1. The binary parsers (asn1/der, cbor/decode, cose/key, x509/chain, webauthn authData/clientData/extensions/rpIdMatch/originCheck/flags) threw ~100 generic `Error`s, so a malformed attestation/assertion left the public API as a bare Error with no `code`. Every throw now carries a PasskeyError code: DECODE_ERROR (new, for der/cbor), AUTH_DATA_INVALID, CLIENT_DATA_INVALID, EXTENSION_INVALID, PUBLIC_KEY_UNSUPPORTED / UNSUPPORTED_ALGORITHM, ATTESTATION_INVALID / ATTESTATION_TRUST_ANCHOR_MISSING, INVALID_ARGUMENT. 2. Removed the 24 per-code `throwXxx = throwFactory(code)` exports (plus the unused non-throwing `invalidArgument`) — a bloat no other package carries. Every call site now constructs the error directly, `throw new PasskeyError(ErrorCode.X, msg)`, exactly like jwt / apikey / session. errors.js is now just ErrorCode + PasskeyError. Messages and control flow are unchanged; the 309-test suite (asserts parser errors by message) passes.
Replace inline typeof / Array.isArray / Number.isInteger with the shared predicates (isString, isFunction, isBoolean, isBigInt, isArray, isInteger, isObject) across the package — the repo convention every other package already follows. Behaviour-preserving: each object check expects a non-array object so array-excluding isObject matches (clientData already rejected arrays explicitly), and every integer site is bounded so isInteger (isSafeInteger) is equivalent. `typeof x === 'number'` checks are left inline on purpose — shared isNumber additionally rejects NaN, which would be a behaviour change. 309 tests green.
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.
What
Two coupled cleanups bringing
@exortek/passkeyerror handling in line with the rest of the repo.1. Typed errors from every parser
The binary parsers —
cbor/decode,asn1/der,cose/key,x509/chain, and the WebAuthnauthData/clientData/extensions/rpIdMatch/originCheck/flagsreaders — threw ~100 genericErrors. A malformed attestation/assertion therefore left the public API as a bareErrorwith nocode, breaking the package's "branch onerr.code" contract.Every throw now carries a
PasskeyErrorcode:ErrorCode.DECODE_ERRORfor low-level CBOR/DER decode failuresAUTH_DATA_INVALID,CLIENT_DATA_INVALID,EXTENSION_INVALIDPUBLIC_KEY_UNSUPPORTED/UNSUPPORTED_ALGORITHM(COSE)ATTESTATION_INVALID/ATTESTATION_TRUST_ANCHOR_MISSING(X.509)INVALID_ARGUMENTfor argument-shape failures2. Drop the per-code throw-factory bloat
Removed the 24
throwXxx = throwFactory(code)exports (+ the unused non-throwinginvalidArgument) — a pattern no other package carries. Every call site now constructs the error directly:throw new PasskeyError(ErrorCode.X, msg), exactly likejwt/apikey/session.errors.jsis now justErrorCode+PasskeyError.3. Shared predicate adoption
Inline
typeof/Array.isArray/Number.isInteger→@exortek/shared/predicates(isString,isObject,isArray, …). Behaviour-preserving (audited: object sites expect non-array objects; integer sites are bounded).typeof x === 'number'checks are left inline on purpose — sharedisNumberalso rejectsNaN, which would change behaviour.Compatibility
indexonly ever re-exportedPasskeyError+ErrorCode.try/catchkeeps working (PasskeyError extends Error);err.codeis now populated for parser failures too.Verification
yarn verifygreen — 2671 tests pass, 0 fail (passkey 309; parser tests assert by message, so retyping is transparent).yarn buildclean;packages/passkey/dist/index.d.tscarriesDECODE_ERROR, nothrowXxx, no@exortek/sharedleak.Minor changeset included (new
DECODE_ERRORcode + typed parser errors).