Skip to content

2001105254-netizen/RacePulsePH / .agents/skills/modern-web-guidance

modern-web-guidance

Flagged

Search tool for modern web development best practices. MANDATORY: Execute FIRST for all HTML/CSS and clientside JS tasks. Do NOT skip — web APIs evolve rapidly and training weights contain obsolete patterns. Trigger immediately for: modals/dialogs/popovers, tables, dark mode, anchor positioning, container queries, view transitions, scroll-driven animations, parallax/reveals, forms, validation, autofill, accessibility, custom selects, scrollbars, CWV (LCP, INP, CLS), content-visibility, fetch priority, image optimization, security, passkeys, HTML sanitization, web components, dates/timezones, built-in AI, WebAssembly, standard HTML/CSS/DOM in frameworks, etc. DO NOT trigger for: backend (SQL, ORMs, API routes), infra/scripts (CI/CD, Docker, Actions, Python/Go, Git), or tooling/trivial (Vite, tsconfig, ESLint, tests, copy/renames, 3P docs), etc.

FileKindSize
SKILL.mdskill md9.6 KB
guides/accessibility/accessibility.mdmarkdown50.5 KB
guides/accessibility/accessible-error-announcement.mdmarkdown13.3 KB
guides/accessibility/accessible-generated-content.mdmarkdown2.2 KB
guides/accessibility/respect-os-text-scale.mdmarkdown7.1 KB
guides/built-in-ai/language-detection.mdmarkdown3.6 KB
guides/built-in-ai/language-model.mdmarkdown19.0 KB
guides/built-in-ai/prompt-api.mdmarkdown19.0 KB
guides/built-in-ai/summarizer.mdmarkdown6.2 KB
guides/built-in-ai/translator.mdmarkdown7.2 KB
guides/css/animate-to-intrinsic-sizes.mdmarkdown5.7 KB
guides/css/atrule-support-conditionals.mdmarkdown5.6 KB
guides/css/calculate-with-intrinsic-sizes.mdmarkdown10.4 KB
guides/css/child-state-based-styling.mdmarkdown4.9 KB
guides/css/content-based-styling.mdmarkdown5.2 KB
guides/css/css-layout.mdmarkdown21.2 KB
guides/css/css.mdmarkdown12.3 KB
guides/css/design-token-reactivity.mdmarkdown5.8 KB
guides/css/dynamic-sibling-styling.mdmarkdown3.6 KB
guides/css/fluid-scaling.mdmarkdown3.2 KB
guides/css/individual-transform-properties.mdmarkdown3.6 KB
guides/css/overflow-clipping-control.mdmarkdown8.1 KB
guides/css/reduce-style-repetition.mdmarkdown3.9 KB
guides/css/responsive-design.mdmarkdown1.8 KB
guides/css/selector-atrule-combinations.mdmarkdown3.6 KB
guides/css/size-aware-styling.mdmarkdown2.9 KB
guides/css/style-parent-with-has.mdmarkdown13.6 KB
guides/css/usage-aware-component-variations.mdmarkdown5.1 KB
guides/forms/animated-select-picker.mdmarkdown8.5 KB
guides/forms/autofill-address-form.mdmarkdown4.9 KB
guides/forms/autofill-highlight-inputs.mdmarkdown3.5 KB
guides/forms/autofill-payment-form.mdmarkdown9.7 KB
guides/forms/autofill-sign-in-form.mdmarkdown10.5 KB
guides/forms/autofill-sign-up-form.mdmarkdown11.6 KB
guides/forms/brand-consistent-forms.mdmarkdown8.4 KB
guides/forms/branded-select-styling.mdmarkdown5.6 KB
guides/forms/custom-select-picker-layouts.mdmarkdown7.8 KB
guides/forms/form-fields-automatically-fit-contents.mdmarkdown5.9 KB
guides/forms/forms.mdmarkdown18.9 KB
guides/forms/ime-safe-enter-submit.mdmarkdown6.3 KB
guides/forms/required-field-feedback.mdmarkdown13.9 KB
guides/forms/rich-media-picker.mdmarkdown10.5 KB
guides/forms/select-menu-interaction.mdmarkdown12.9 KB
guides/forms/slider.mdmarkdown6.5 KB
guides/forms/sms-otp-form.mdmarkdown12.5 KB
guides/forms/switch.mdmarkdown2.5 KB
guides/forms/validate-input-after-interaction.mdmarkdown17.2 KB
guides/html/accessible-web-components.mdmarkdown5.1 KB
guides/html/custom-elements.mdmarkdown9.3 KB
guides/html/form-associated-custom-elements.mdmarkdown4.9 KB
guides/html/html.mdmarkdown20.8 KB
guides/html/prerendering-custom-elements.mdmarkdown3.6 KB
guides/html/shadow-dom.mdmarkdown3.8 KB
guides/html/styling-web-components.mdmarkdown8.7 KB
guides/html/web-components.mdmarkdown6.6 KB
guides/js/calculate-event-differentials.mdmarkdown8.3 KB
guides/js/capture-location-agnostic-data.mdmarkdown9.7 KB
guides/js/coordinate-global-events.mdmarkdown4.0 KB
guides/js/sort-high-precision-timestamps.mdmarkdown6.6 KB
guides/js/support-global-calendar-systems.mdmarkdown5.8 KB
guides/performance/batch-analytics-events.mdmarkdown6.4 KB
guides/performance/break-up-long-tasks.mdmarkdown2.2 KB
guides/performance/calculate-total-foreground-time.mdmarkdown2.9 KB
guides/performance/conditional-async-dependencies.mdmarkdown5.3 KB
guides/performance/defer-rendering-heavy-content.mdmarkdown6.3 KB
guides/performance/defer-work-until-scroll-ends.mdmarkdown3.3 KB
guides/performance/deliver-optimized-decorative-images.mdmarkdown2.8 KB
guides/performance/deprioritize-background-fetches.mdmarkdown1.8 KB
guides/performance/detect-initial-visibility-state.mdmarkdown4.6 KB
guides/performance/efficient-background-processing.mdmarkdown5.0 KB
guides/performance/faster-spa-view-transitions.mdmarkdown3.6 KB
guides/performance/flicker-free-client-side-ab-testing.mdmarkdown8.5 KB
guides/performance/full-session-analytics.mdmarkdown5.7 KB
guides/performance/identify-heavy-scripts.mdmarkdown4.2 KB
guides/performance/identify-inp-causes.mdmarkdown8.7 KB
guides/performance/improve-next-page-load-performance.mdmarkdown7.2 KB
guides/performance/interaction-paint-timing.mdmarkdown11.2 KB
guides/performance/interactions-in-complex-layouts.mdmarkdown3.4 KB
guides/performance/lazy-load-video-and-audio.mdmarkdown9.3 KB
guides/performance/optimize-image-priority.mdmarkdown4.5 KB
guides/performance/optimize-preload-priority.mdmarkdown3.3 KB
guides/performance/optimize-script-priority.mdmarkdown2.6 KB
guides/performance/out-of-order-html-streaming.mdmarkdown12.1 KB
guides/performance/performance.mdmarkdown20.6 KB
guides/performance/resolution-optimized-pseudo-elements.mdmarkdown2.3 KB
guides/performance/schedule-tasks-by-priority.mdmarkdown2.3 KB
guides/privacy/privacy.mdmarkdown11.0 KB
guides/pwa/install-web-app.mdmarkdown15.0 KB
guides/pwa/migrate-web-app-origin.mdmarkdown3.6 KB
guides/security/client-side-encryption.mdmarkdown14.8 KB
guides/security/digital-signatures.mdmarkdown9.9 KB
guides/security/local-network-access.mdmarkdown12.3 KB
guides/security/passkey-authentication.mdmarkdown11.5 KB
guides/security/passkey-conditional-create.mdmarkdown7.9 KB
guides/security/passkey-management.mdmarkdown17.3 KB
guides/security/passkey-reauthentication.mdmarkdown6.4 KB
guides/security/passkey-registration.mdmarkdown10.3 KB
guides/security/passkeys.mdmarkdown4.9 KB
guides/security/quick-sign-ins.mdmarkdown17.5 KB
guides/security/restrict-outbound-connections.mdmarkdown13.2 KB
guides/security/sanitize-untrusted-html.mdmarkdown5.6 KB
guides/security/secure-external-subresources.mdmarkdown14.5 KB
guides/security/security.mdmarkdown29.3 KB
guides/security/trusted-types.mdmarkdown7.3 KB
guides/security/validate-origins.mdmarkdown12.7 KB
guides/security/verify-email-ownership.mdmarkdown14.5 KB
guides/ui-atoms/carousel-slide-effects.mdmarkdown10.1 KB
guides/ui-atoms/component-specific-light-dark-theme.mdmarkdown9.5 KB
guides/ui-atoms/icons.mdmarkdown17.9 KB
guides/ui-atoms/position-aware-tooltips.mdmarkdown8.3 KB
guides/ui-atoms/pull-to-reveal.mdmarkdown5.0 KB
guides/ui-atoms/responsive-table.mdmarkdown4.4 KB
guides/ui-atoms/scroll-position-aware-elements.mdmarkdown3.6 KB
guides/ui-atoms/scroll-progress-indicator.mdmarkdown6.6 KB
guides/ui-atoms/scrollability-affordance-hints.mdmarkdown11.9 KB
guides/ui-atoms/shrinking-header-on-scroll.mdmarkdown7.0 KB
guides/ui-atoms/single-line-overflow.mdmarkdown16.1 KB
guides/ui-atoms/state-aware-sticky-headers.mdmarkdown6.7 KB
guides/ui-atoms/viewport-aware-dropdowns.mdmarkdown9.9 KB
guides/ui-behaviors/2d-panning.mdmarkdown9.2 KB
guides/ui-behaviors/anchor-positioning-tab-underline.mdmarkdown3.1 KB
guides/ui-behaviors/animate-element-entry-exit.mdmarkdown7.7 KB
guides/ui-behaviors/animate-to-from-top-layer.mdmarkdown10.7 KB
guides/ui-behaviors/carousel-snap-highlights.mdmarkdown7.5 KB
guides/ui-behaviors/consistent-cross-document-transitions.mdmarkdown13.9 KB
guides/ui-behaviors/cross-document-transitions.mdmarkdown4.4 KB
guides/ui-behaviors/custom-button-actions.mdmarkdown8.2 KB
guides/ui-behaviors/declarative-dialog-popover-control.mdmarkdown7.6 KB
guides/ui-behaviors/directional-navigation-transitions.mdmarkdown5.1 KB
guides/ui-behaviors/drag-and-drop.mdmarkdown16.4 KB
guides/ui-behaviors/drag.mdmarkdown6.8 KB
guides/ui-behaviors/dynamic-sibling-animations.mdmarkdown2.6 KB
guides/ui-behaviors/dynamic-sort.mdmarkdown6.9 KB
guides/ui-behaviors/group-element-transitions.mdmarkdown6.2 KB
guides/ui-behaviors/highlight-text-ranges.mdmarkdown6.4 KB
guides/ui-behaviors/interactive-content-reveal.mdmarkdown5.7 KB
guides/ui-behaviors/interest-triggered-action-previews.mdmarkdown4.9 KB
guides/ui-behaviors/interest-triggered-tooltips.mdmarkdown19.8 KB
guides/ui-behaviors/light-dismiss-a-dialog.mdmarkdown4.1 KB
guides/ui-behaviors/motion.mdmarkdown7.6 KB
guides/ui-behaviors/move-dom-element-without-losing-state.mdmarkdown3.8 KB
guides/ui-behaviors/parallax-scroll-effects.mdmarkdown9.5 KB
guides/ui-behaviors/persistent-top-layer-ui.mdmarkdown2.3 KB
guides/ui-behaviors/physics-based-easing.mdmarkdown5.8 KB
guides/ui-behaviors/platform-controls-dismiss-dialog.mdmarkdown2.6 KB
guides/ui-behaviors/prevent-page-scroll-under-modal-dialog.mdmarkdown5.0 KB
guides/ui-behaviors/same-document-transitions.mdmarkdown8.3 KB
guides/ui-behaviors/scoped-component-transitions.mdmarkdown11.7 KB
guides/ui-behaviors/scroll-completion-effects.mdmarkdown7.5 KB
guides/ui-behaviors/scroll-entry-exit-effects.mdmarkdown9.8 KB
guides/ui-behaviors/scroll-snap-realtime-feedback.mdmarkdown10.7 KB
guides/ui-behaviors/scroll-snap-state-sync.mdmarkdown4.8 KB
guides/ui-behaviors/scroll-target-on-load.mdmarkdown3.4 KB
guides/ui-behaviors/scrollytelling.mdmarkdown8.8 KB
guides/ui-behaviors/search-hidden-content.mdmarkdown6.8 KB
guides/ui-behaviors/sortable-table.mdmarkdown7.7 KB
guides/ui-behaviors/spatial-navigation.mdmarkdown6.8 KB
guides/ui-behaviors/swipe-to-remove.mdmarkdown33.9 KB
guides/ui-behaviors/swipe-to-reveal.mdmarkdown14.2 KB
guides/ui-components/accordion.mdmarkdown14.7 KB
guides/ui-components/app-menus.mdmarkdown15.7 KB
guides/ui-components/breadcrumbs.mdmarkdown12.3 KB
guides/ui-components/card.mdmarkdown8.2 KB
guides/ui-components/carousel.mdmarkdown15.1 KB
guides/ui-components/checkbox.mdmarkdown5.7 KB
guides/ui-components/copy-button.mdmarkdown14.5 KB
guides/ui-components/dark-mode-toggle.mdmarkdown9.2 KB
guides/ui-components/dialog.mdmarkdown12.1 KB
guides/ui-components/hovercard.mdmarkdown20.9 KB
guides/ui-components/menu.mdmarkdown31.1 KB
guides/ui-components/navbar.mdmarkdown17.8 KB
guides/ui-components/navigation-drawer.mdmarkdown20.3 KB
guides/ui-components/persistent-app-tours.mdmarkdown11.2 KB
guides/ui-components/persistent-toast-notifications.mdmarkdown13.8 KB
guides/ui-components/progress-ring.mdmarkdown6.9 KB
guides/ui-components/progress.mdmarkdown10.6 KB
guides/ui-components/scrollspy.mdmarkdown6.9 KB
guides/ui-components/spinner.mdmarkdown5.9 KB
guides/ui-components/stack-drill-down.mdmarkdown36.5 KB
guides/ui-components/tabs.mdmarkdown21.7 KB
guides/ui-components/toolbar.mdmarkdown21.5 KB
guides/user-experience/content-first-noise-reduction.mdmarkdown8.3 KB
guides/user-experience/form-factor-adaptation.mdmarkdown6.0 KB
guides/user-experience/natural-interactions.mdmarkdown9.7 KB
guides/visual-design/adapt-scrollbar-to-contrast-preferences.mdmarkdown3.6 KB
guides/visual-design/apply-webgl-shaders.mdmarkdown13.1 KB
guides/visual-design/browser-ui-theming.mdmarkdown4.1 KB
guides/visual-design/color.mdmarkdown4.4 KB
guides/visual-design/complex-shapes.mdmarkdown3.5 KB
guides/visual-design/contrast-color.mdmarkdown7.1 KB
guides/visual-design/custom-text-decorations.mdmarkdown16.4 KB
guides/visual-design/customize-scrollbar-color-and-thickness.mdmarkdown2.7 KB
guides/visual-design/dark-mode.mdmarkdown16.8 KB
guides/visual-design/equal-width-text-lines.mdmarkdown6.4 KB
guides/visual-design/export-html-media-from-canvas.mdmarkdown17.1 KB
guides/visual-design/expose-canvas-content-to-browser-features.mdmarkdown19.6 KB
guides/visual-design/improve-text-layout-and-legibility.mdmarkdown5.1 KB
guides/visual-design/interactive-content-in-3d-scenes.mdmarkdown19.2 KB
guides/visual-design/precise-text-alignment.mdmarkdown4.8 KB
guides/visual-design/shaped-cutouts.mdmarkdown7.1 KB

guides/security/digital-signatures.md

View on GitHub
# Sign and verify data with WebCrypto

Use the Web Cryptography API (`crypto.subtle`) to sign and verify messages, tokens, or artifacts in the browser using quantum-resistant (ML-DSA) or classical (`'Ed25519'`, `'ECDSA'`) asymmetric keys. Digital signatures guarantee data integrity and signer authenticity without requiring shared secret keys. For establishing shared secrets and encrypting confidential payloads, see `client-side-encryption` (via `npx -y modern-web-guidance@latest retrieve "client-side-encryption"`).

## 1. Choose an algorithm and generate a key pair

ML-DSA (Module-Lattice-Based Digital Signature Algorithm, standardized in NIST FIPS 204) provides post-quantum lattice-based digital signatures resistant to attacks by both classical and quantum computers.

Use **`'ML-DSA-65'`** by default for general-purpose signing. Choose `'ML-DSA-44'` when you need smaller public keys and signatures over bandwidth-constrained channels and 128-bit security is sufficient, or `'ML-DSA-87'` when a security policy requires NIST Category 5 (CNSA 2.0) compliance.

| Algorithm name | Security level & use case | Public key (`'raw-public'`) | Signature size |
|---|---|---|---|
| `'ML-DSA-44'` | NIST Category 2 (~128-bit security); smallest keys and signatures | 1312 bytes | 2420 bytes |
| **`'ML-DSA-65'`** | **NIST Category 3 (~192-bit security); recommended default** | 1952 bytes | 3309 bytes |
| `'ML-DSA-87'` | NIST Category 5 (~256-bit security); highest security margin | 2592 bytes | 4627 bytes |

- Pass `'ML-DSA-44'`, `'ML-DSA-65'`, or `'ML-DSA-87'` as the algorithm name (pre-standardization names such as `'Dilithium'` or `'CRYSTALS-Dilithium'` throw `NotSupportedError`).
- Neither ML-DSA nor `'Ed25519'` takes a `hash` parameter.
- Pass `['sign', 'verify']` when generating a key pair with `generateKey()`:

```javascript
const signerKeyPair = await crypto.subtle.generateKey(
  'ML-DSA-65',
  false,
  ['sign', 'verify'],
);
```

## 2. Export and import keys

`'ML-DSA-44'`, `'ML-DSA-65'`, and `'ML-DSA-87'` **reject the legacy `'raw'` format** in `importKey()` and `exportKey()` with a `NotSupportedError`. Always export or import keys using an explicit format:

- **`'raw-public'`**: Public key bytes (`1312`, `1952`, or `2592` bytes). Pass `['verify']` as the key usage when importing a public key.
- **`'raw-seed'`**: 32-byte private key seed for all three ML-DSA algorithms. Both `'raw'` and `'raw-private'` throw `NotSupportedError` on ML-DSA—store or transmit private keys using `'raw-seed'`, `'pkcs8'` (54 bytes), or `'jwk'` (`kty: 'AKP'`). Pass `['sign']` as the key usage when importing a private key (passing `['sign', 'verify']` to `importKey()` throws `SyntaxError`).
- **`'spki'`, `'pkcs8'`, and `'jwk'`**: Supported for all three ML-DSA algorithms.

Always export the verification public key with `'raw-public'` so the public key bytes can be serialized or shared with verifiers:

```javascript
// Export the public key bytes on the signer
const publicKeyBytes = await crypto.subtle.exportKey(
  'raw-public',
  signerKeyPair.publicKey,
);

// Import the public key bytes on the verifier (usage must be ['verify'] only)
const verifierPublicKey = await crypto.subtle.importKey(
  'raw-public',
  publicKeyBytes,
  'ML-DSA-65',
  true,
  ['verify'],
);
```

If you only hold a private signing `CryptoKey` (even with `extractable: false`) and need its corresponding public `CryptoKey`, call `crypto.subtle.getPublicKey()` with `['verify']`:

```javascript
const publicKey = await crypto.subtle.getPublicKey(
  signerKeyPair.privateKey,
  ['verify'],
);
```

## 3. Sign and verify payloads

Call `crypto.subtle.sign()` with the private key to produce a signature, and `crypto.subtle.verify()` with the public key to check it:

```javascript
const payloadBytes = new TextEncoder().encode(
  '{"artifact":"release-v2.4.0.tar.gz","sha256":"9f86d08..."}',
);

const signatureBuffer = await crypto.subtle.sign(
  'ML-DSA-65',
  signerKeyPair.privateKey,
  payloadBytes,
);

const isValid = await crypto.subtle.verify(
  'ML-DSA-65',
  verifierPublicKey,
  signatureBuffer,
  payloadBytes,
);
```

### Domain separation with `ContextParams`

To prevent a signature created for one purpose from being replayed in another part of your application or protocol that shares the same key pair, bind the signature to a domain-separation `context`.

Instead of a bare algorithm name string, pass a `ContextParams` dictionary (`{ name, context }`) to `sign()` and `verify()`, where `context` is a `BufferSource` (`Uint8Array` or `ArrayBuffer`):

```javascript
const contextBytes = new TextEncoder().encode('release-manifest-v1');

const signatureBuffer = await crypto.subtle.sign(
  {
    name: 'ML-DSA-65',
    context: contextBytes,
  },
  signerKeyPair.privateKey,
  payloadBytes,
);

const isValid = await crypto.subtle.verify(
  {
    name: 'ML-DSA-65',
    context: contextBytes,
  },
  verifierPublicKey,
  signatureBuffer,
  payloadBytes,
);
```

- **255-byte limit**: `context` accepts `0` to `255` bytes (omitting `context` is equivalent to passing an empty `new Uint8Array(0)`). Passing more than `255` bytes rejects with `OperationError`.
- **Exact match required**: `crypto.subtle.verify()` returns `true` only when the verifier passes the exact same `context` bytes used during `crypto.subtle.sign()`.

## Fallback strategies

Baseline status for Web Cryptography: Widely available. It's been Baseline since 2017-09-19.
Supported by: Chrome 37 (Aug 2014), Edge 12 (Jul 2015), Firefox 34 (Dec 2014), and Safari 11 (Sep 2017).

Baseline status for the api.SubtleCrypto.sign.ed25519 capability: Newly available. It's been Baseline since 2025-05-29.
Supported by: Chrome 137 (May 2025), Edge 137 (May 2025), Firefox 129 (Aug 2024), and Safari 17 (Sep 2023).

If your Baseline target does not yet support `SubtleCrypto.supports()` or ML-DSA, detect support using the **static** `SubtleCrypto.supports()` method and fall back to classical `'Ed25519'` (or `'ECDSA'` with `'P-256'` and `'SHA-256'` when targeting browsers prior to `'Ed25519'` support):

- **Call `SubtleCrypto.supports()` on the `SubtleCrypto` constructor, not on `crypto.subtle`**: `globalThis.SubtleCrypto?.supports?.('sign', 'ML-DSA-65')` is a synchronous static method returning a boolean (`crypto.subtle.supports` is `undefined`). Probe `'sign'`, `'verify'`, `'generateKey'`, `'importKey'`, `'exportKey'`, or `'getPublicKey'` (or pass a `ContextParams` dictionary such as `SubtleCrypto.supports('sign', { name: 'ML-DSA-65', context })`).
- **Key format in the fallback (`'raw'`)**: While browsers that support Modern WebCrypto also accept `'raw-public'` on `'Ed25519'` and `'ECDSA'`, use `'raw'` in fallback paths targeting older browsers.
- **Domain separation in the fallback**: Classical WebCrypto algorithms (`'Ed25519'` and `'ECDSA'`) do not read a `context` property from the algorithm dictionary (WebIDL silently ignores unknown dictionary properties on `Algorithm` and `EcdsaParams`). Prepend a length-prefixed `context` header to the payload in your fallback path so domain separation behaves consistently across both suites.

```javascript
const ML_DSA_PUBLIC_KEY_ALGORITHMS = {
  1312: 'ML-DSA-44',
  1952: 'ML-DSA-65',
  2592: 'ML-DSA-87',
};

export function supportsPostQuantumSignatures() {
  return (
    typeof globalThis.SubtleCrypto?.supports === 'function' &&
    SubtleCrypto.supports('sign', 'ML-DSA-65')
  );
}

export async function generateSigningKeyPair() {
  if (supportsPostQuantumSignatures()) {
    const keyPair = await crypto.subtle.generateKey('ML-DSA-65', false, ['sign', 'verify']);
    const publicKeyBytes = new Uint8Array(
      await crypto.subtle.exportKey('raw-public', keyPair.publicKey),
    );
    return {
      suite: 'ML-DSA-65',
      keyFormat: 'raw-public',
      keyPair,
      publicKeyBytes,
    };
  }

  // Classical fallback: Ed25519
  const keyPair = await crypto.subtle.generateKey('Ed25519', false, ['sign', 'verify']);
  const publicKeyBytes = new Uint8Array(await crypto.subtle.exportKey('raw', keyPair.publicKey));
  return {
    suite: 'Ed25519',
    keyFormat: 'raw',
    keyPair,
    publicKeyBytes,
  };
}

function frameFallbackInput(payloadBytes, contextBytes) {
  if (contextBytes.byteLength > 255) {
    throw new DOMException('Context must not exceed 255 bytes', 'OperationError');
  }
  const framed = new Uint8Array(1 + contextBytes.byteLength + payloadBytes.byteLength);
  framed[0] = contextBytes.byteLength;
  framed.set(contextBytes, 1);
  framed.set(payloadBytes, 1 + contextBytes.byteLength);
  return framed;
}

export async function signPayload(
  privateKey,
  payloadBytes,
  contextBytes = new Uint8Array(0),
) {
  if (privateKey.algorithm.name.startsWith('ML-DSA')) {
    const sig = await crypto.subtle.sign(
      { name: privateKey.algorithm.name, context: contextBytes },
      privateKey,
      payloadBytes,
    );
    return new Uint8Array(sig);
  }

  const framed = frameFallbackInput(payloadBytes, contextBytes);
  const sig = await crypto.subtle.sign('Ed25519', privateKey, framed);
  return new Uint8Array(sig);
}

export async function verifyPayload(
  publicKeyOrBytes,
  signatureBytes,
  payloadBytes,
  contextBytes = new Uint8Array(0),
) {
  const publicKey =
    publicKeyOrBytes instanceof CryptoKey
      ? publicKeyOrBytes
      : await (() => {
          const bytes =
            publicKeyOrBytes instanceof Uint8Array
              ? publicKeyOrBytes
              : new Uint8Array(publicKeyOrBytes);
          const mlDsaName = ML_DSA_PUBLIC_KEY_ALGORITHMS[bytes.byteLength];
          return mlDsaName
            ? crypto.subtle.importKey('raw-public', bytes, mlDsaName, true, ['verify'])
            : crypto.subtle.importKey('raw', bytes, 'Ed25519', true, ['verify']);
        })();

  if (publicKey.algorithm.name.startsWith('ML-DSA')) {
    return crypto.subtle.verify(
      { name: publicKey.algorithm.name, context: contextBytes },
      publicKey,
      signatureBytes,
      payloadBytes,
    );
  }

  const framed = frameFallbackInput(payloadBytes, contextBytes);
  return crypto.subtle.verify('Ed25519', publicKey, signatureBytes, framed);
}
```
rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first.Stars: 194kUpdated Claude CodeCodexVerifiedInstall