Skip to content

Conversation

@AkshatM
Copy link
Contributor

@AkshatM AkshatM commented Dec 18, 2025

http-message-sig package is currently not compliant with the spec - in particular, it returns @authority as a derived component in the response, when in reality it should be returning "@authority";req.

This makes it impossible to write a compliant HTTP message directory, for instance.

To support this, I've made several changes:

  1. I've defined a new type called ComponentParameters, which can store arbitrary parameters attached to components. This allows us to expose req, bs, sf, etc. and even key.

  2. I've replaced the handwritten parser with structured-headers library, which does the parsing for us. I've done my best to preserve the error cases we had in the past, but I've removed cases that assumed an unknown parameter meant invalid parsing - unknown list parameters are fine to keep and do not imply invalid parsing.

  3. I've altered all the signing and verifying functions to accept either a RequestLike or a pair of ResponseLike and an optional RequestLike, instead of a raw ResponseLike. This allows all signers and verifiers to have access to the request.

@AkshatM AkshatM requested a review from thibmeu December 18, 2025 00:40
@AkshatM
Copy link
Contributor Author

AkshatM commented Dec 18, 2025

@thibmeu I'm not quite sure how to resolve these build errors - tsup is a mystery to me. Can you take a quick look?

I ran npm run test locally, and all the tests for http-message-sig pass - web-bot-auth is unable to import http-message-sig, though, which I suspect is related.

@AkshatM AkshatM force-pushed the akshat/update-typescript-to-support-req branch from e73aa76 to e5eda65 Compare December 18, 2025 00:58
Copy link
Collaborator

@thibmeu thibmeu left a comment

Choose a reason for hiding this comment

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

The change is correct, but sacrifices a lot of the developer experience.

  1. '@authority' becomes {name: '@authority'}``
  2. Responses as parameter becomes {response: Response}

As a follow up, it could also be interesting to have some performance measurements.

For tsup, you can add the following tsconfig.json under packages/http-message-sig, similar to the one present in web-bot-auth

For building, as long as you do it from the root, it should work. It seems web-bot-auth package needs update based on your API changes in http-message-sig. Ideally, the package would not need any type update (or more limited, based on the DX comments)

{
  "compilerOptions": {
    "target": "es2021",
    "module": "es2022",
    "moduleResolution": "bundler",
    "skipLibCheck": true
  }
}

parameters?: ComponentParameters;
}

export type ComponentParameters = Map<string, string | boolean>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this have to be a map, or are you looking for Record<string, string|boolean>? https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkeys-type

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A map is what the structured-header package uses to represent component parameters. I found it quite useful, since it means you automatically have access to .has(), .get(), .set() + guarantees on iteration order, and supports arbitrary parameters - it feels like the "correct" interface.

What is the advantage of a record type here? That is, what are we trying to preserve?

@AkshatM AkshatM force-pushed the akshat/update-typescript-to-support-req branch from e5eda65 to 2aba1db Compare December 18, 2025 16:31
`http-message-sig` package is currently not compliant with the spec - in
particular, it returns `@authority` as a derived component in the
response, when in reality it should be returning `"@authority";req`.

This makes it impossible to write a compliant HTTP message directory,
for instance.

To support this, I've made several changes:

1. I've defined a new type called `ComponentParameters`, which can store
   arbitrary parameters attached to components. This allows us to expose
   `req`, `bs`, `sf`, etc. and even `key`. I've added it as a variant of
   `Component`.

2. I've replaced the handwritten parser with `structured-headers`
   library, which does the parsing for us. I've done my best to
   preserve the error cases we had in the past, but I've removed cases
   that assumed an unknown parameter meant invalid parsing - unknown
   list parameters are fine to keep and do not imply invalid parsing.

3. I've defined a new type called `ResponseRequestPair`, which bundles
   both request and response together, and written a resolver that
   inspects whether or not a component needs the pair, or can make do
   with just the raw message.
@AkshatM AkshatM force-pushed the akshat/update-typescript-to-support-req branch from 2aba1db to 31b586c Compare December 18, 2025 17:01
@AkshatM
Copy link
Contributor Author

AkshatM commented Dec 18, 2025

npm run lint was erroring in CI earlier, so I fixed it locally with npm run format and a .prettierignore file that stopped prettier from (inexplicably) running on binary files produced as part of the build step.

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