feat(crypto): add createAuthChainHeaders utility - #54
Open
decentraland-bot wants to merge 1 commit into
Open
Conversation
Serializes a signed AuthChain into the x-identity-* signed-fetch headers next to the header-name constants it depends on, removing the need for downstream packages to duplicate this logic. Closes #53
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
createAuthChainHeaders(authChain, timestamp, metadata?)export to@dcl/crypto, placed inlibs/crypto/src/headers.tsnext to theAUTH_CHAIN_HEADER_PREFIX/AUTH_TIMESTAMP_HEADER/AUTH_METADATA_HEADERconstants it serializes into.AuthChainremainsAuthenticator.signPayload's job.Record<string, string>headers object (not a JSON blob), so HTTP consumers can spread it directly intofetchheaders, while consumers needing a serialized blob (e.g. Pulse's protoauth_chainfield) canJSON.stringify()the result themselves.libs/crypto/src/index.ts'sexport * from './headers'.minorchangeset for@dcl/crypto.Why
This exact serialization logic is currently duplicated in the ecosystem:
libs/crypto-middleware/src/createAuthChainHeaders.ts(this same monorepo) — its own copy, already importing the header-name constants from@dcl/cryptovia a deprecated re-export.@dcl/pulse-client'sbuildAuthChain— the serialization half.Centralizing it in
@dcl/cryptoremoves that duplication and keeps the serialization next to the constants it depends on. Migratinglibs/crypto-middlewareand@dcl/pulse-clientonto this shared implementation is a follow-up, gated on a published@dcl/cryptorelease containing this change.Plan
libs/cryptoconventions:headers.tshouses the three signed-fetch header constants;AuthChainis defined inlibs/crypto/src/types.ts(re-exported from@dcl/schemas); tests use Jest with nesteddescribe/when/itblocks (mirrored fromlibs/crypto/test/unit/sanity.spec.tsandlibs/crypto-middleware/test/unit/helpers.spec.ts, which has its owncreateAuthChainHeaderstest as a direct behavioral reference); the repo uses@changesets/clifor versioning; scripts arebuild(tsc),test(jest),lint/lint:fix(eslint, prettier-integrated).createAuthChainHeadersinlibs/crypto/src/headers.ts, importing the existing constants and theAuthChaintype — no redefinition.libs/crypto/test/unit/headers.spec.tscovering: multi-link chain → oneAUTH_CHAIN_HEADER_PREFIX{i}entry per link (JSON-stringified); single-link chain; timestamp stringification; metadata defaulting to{}when omitted; metadata JSON-stringified when provided. (No round-trip test: the header-parsing counterpart,extractAuthChain/verify, lives in the separate@dcl/crypto-middlewarepackage, not in@dcl/cryptoitself.)minorchangeset (@dcl/cryptogains a new public export).build/test/lintforlibs/crypto, then repo-widepnpm build/pnpm lint/pnpm test(all 9 workspace packages) andpnpm changeset status --since=origin/main(correctly reports@dcl/cryptofor aminorbump, with internal dependents auto-bumpedpatchperupdateInternalDependencies).Changes
Testing
pnpm build(repo-wide, 9 packages) — passpnpm lint(repo-wide) — pass (one prettier formatting issue in the new test file was auto-fixed vialint:fix)pnpm test(repo-wide) — pass, including 5 new assertions inlibs/crypto/test/unit/headers.spec.ts(55/55 tests passing inlibs/crypto)pnpm changeset status --since=origin/main— confirms@dcl/cryptois queued for aminorbumpCloses
Closes #53
🤖 Created via Slack with Claude
Requested by Gabriel Díaz via Slack