@request-seal/core 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/CHANGELOG.md +34 -1
  2. package/README.md +10 -9
  3. package/dist/adapters/node-http/index.d.ts +8 -1
  4. package/dist/adapters/node-http/index.js +21 -5
  5. package/dist/constants.d.ts +4 -4
  6. package/dist/constants.js +2 -2
  7. package/dist/crypto/algorithm.d.ts +4 -0
  8. package/dist/crypto/algorithm.js +12 -0
  9. package/dist/discovery/body.d.ts +12 -2
  10. package/dist/discovery/body.js +33 -11
  11. package/dist/discovery/cache.d.ts +13 -3
  12. package/dist/discovery/cache.js +103 -39
  13. package/dist/discovery/headers.d.ts +2 -0
  14. package/dist/discovery/headers.js +27 -1
  15. package/dist/discovery/index.d.ts +9 -2
  16. package/dist/discovery/index.js +22 -6
  17. package/dist/discovery/node.d.ts +6 -2
  18. package/dist/discovery/node.js +124 -18
  19. package/dist/discovery/proof.js +2 -2
  20. package/dist/discovery/snapshot.js +3 -0
  21. package/dist/errors/parity.d.ts +29 -3
  22. package/dist/errors/parity.js +32 -3
  23. package/dist/errors/types.d.ts +4 -2
  24. package/dist/errors/types.js +14 -2
  25. package/dist/jose/nested.js +23 -1
  26. package/dist/message/index.js +2 -1
  27. package/dist/policy.d.ts +13 -1
  28. package/dist/policy.js +13 -1
  29. package/dist/quorum/evaluation.d.ts +1 -1
  30. package/dist/quorum/evaluation.js +18 -4
  31. package/dist/replay/postgres.d.ts +2 -0
  32. package/dist/replay/postgres.js +6 -0
  33. package/dist/sign.d.ts +22 -1
  34. package/dist/sign.js +25 -4
  35. package/dist/signature-fields.d.ts +5 -1
  36. package/dist/signature-fields.js +9 -1
  37. package/dist/verify-quorum.js +29 -8
  38. package/dist/verify.d.ts +19 -1
  39. package/dist/verify.js +32 -5
  40. package/dist/web-bot-auth/verify.js +2 -2
  41. package/package.json +13 -1
package/dist/verify.js CHANGED
@@ -10,7 +10,7 @@ import { isPublicKey } from "./public_key.js";
10
10
  import { isKeyIdentity, KeyIdentity } from "./key_identity.js";
11
11
  import { build } from "./signature-base/index.js";
12
12
  import { digestField, checkDigest, isDigestState } from "./digest.js";
13
- import { label, dictionaries, validInner, parameters, identities, ensure, fail, bounded, } from "./signature-fields.js";
13
+ import { label, dictionaries, validInner, parameters, identities, ensure, fail, bounded, envelope, } from "./signature-fields.js";
14
14
  import { completed, } from "./verification.js";
15
15
  import { createClaim, retainUntil as retention } from "./replay/claim.js";
16
16
  import { createReceipt } from "./replay/receipt.js";
@@ -371,17 +371,44 @@ export async function verifyLabel(message, policy, options, observeIdentity, par
371
371
  profile, content: contentResult.value, freshness: fresh,
372
372
  replay: replayFacts, principal: "unattributed", authorization: "not_evaluated",
373
373
  });
374
- if (result.ok && identity)
375
- observeIdentity(identity);
374
+ if (result.ok && identity) {
375
+ // An extension pipeline step is a caller callback: its fault keeps the
376
+ // profile's deliberate invalid_policy classification, like a failing
377
+ // signer keeps signer_failed.
378
+ try {
379
+ observeIdentity(identity);
380
+ }
381
+ catch {
382
+ fail("invalid_policy", "input");
383
+ }
384
+ }
376
385
  return result;
377
386
  }
378
387
  catch (e) {
379
388
  if (isRequestSealError(e) && e.kind === "custody" && e.reason === "deadline_exceeded")
380
389
  return err(e);
381
- return err(bounded(e, typeof profile.name === "string" ? "invalid_options" : "invalid_policy", "input"));
390
+ return err(envelope(e));
382
391
  }
383
392
  }
384
- /** Verify one HTTP signature under an explicit branded policy. */
393
+ /**
394
+ * Verify one HTTP signature under an explicit branded policy.
395
+ *
396
+ * Checks exactly the named label; it never tries other labels. Success means the
397
+ * cryptography, coverage, freshness, content, and replay layers all passed. It does not
398
+ * authorize: the Verification records `authorization: "not_evaluated"`.
399
+ *
400
+ * @param message - A branded Message carrying the signature.
401
+ * @param policy - A branded Policy from `Policy.create`.
402
+ * @param options - `{label, context?, representation?, digestState?}`. `representation` is a
403
+ * complete retained Body and needs a `"representation"` content policy. `digestState` is a
404
+ * DigestState of the policy's content kind that you fed with a streamed body; verify finishes
405
+ * it. The two are mutually exclusive.
406
+ * @returns `ok(verification)`, or a bounded error such as `core` `crypto.invalid_signature`,
407
+ * `freshness.expired`, `content.digest_mismatch`, `key.unknown_key`, or `replay.replayed`.
408
+ * @see [Signing and verifying guide](https://github.com/baselabs/request-seal-typescript/blob/main/docs/guides/signing-and-verifying.md),
409
+ * [reference](https://github.com/baselabs/request-seal-typescript/blob/main/docs/reference/sign-and-verify.md), and the
410
+ * [error reasons](https://github.com/baselabs/request-seal-typescript/blob/main/docs/reference/errors.md).
411
+ */
385
412
  export function verify(message, policy, options) {
386
413
  return verifyLabel(message, policy, options);
387
414
  }
@@ -10,7 +10,7 @@ import { isDiscoverySource, sourceOrigin, thumbprintId, } from "../discovery/sou
10
10
  import { isKeySet, isResolution } from "../discovery/body.js";
11
11
  import { isPublicKey } from "../public_key.js";
12
12
  import { coreError, isRequestSealError, } from "../errors/types.js";
13
- import { dictionaries, validInner, parameters, identities, ensure, fail, bounded, } from "../signature-fields.js";
13
+ import { dictionaries, validInner, parameters, identities, ensure, fail, envelope, } from "../signature-fields.js";
14
14
  import { CLOCK_MAX_SECONDS } from "../constants.js";
15
15
  import { retentionEnd } from "../replay/claim.js";
16
16
  import { agents, identifier, originAgent, component, required, nested, schemas, } from "./support.js";
@@ -336,7 +336,7 @@ export async function verifyWebBotAuth(message, policy, options = {}) {
336
336
  catch (e) {
337
337
  if (isRequestSealError(e))
338
338
  return err(e);
339
- return err(bounded(e, "invalid_options", "input"));
339
+ return err(envelope(e));
340
340
  }
341
341
  finally {
342
342
  if (owned)
package/package.json CHANGED
@@ -1,9 +1,21 @@
1
1
  {
2
2
  "name": "@request-seal/core",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Standards-based HTTP message signatures and JOSE for web-standard runtimes.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
7
+ "keywords": [
8
+ "http-message-signatures",
9
+ "rfc9421",
10
+ "rfc9530",
11
+ "content-digest",
12
+ "web-bot-auth",
13
+ "jose",
14
+ "jws",
15
+ "jwe",
16
+ "webcrypto",
17
+ "replay-protection"
18
+ ],
7
19
  "main": "./dist/index.js",
8
20
  "types": "./dist/index.d.ts",
9
21
  "exports": {