Skip to content
Documentation
1.0.0-beta.10 · latest

ES256 bearer verification

Source e69e4b6f1381 · Published v1.0.0-beta.10

This Node example verifies one bearer JWT with an inline public P-256 JWK. The Native profile links the released RustCrypto verifier explicitly and does not probe for a fallback realization.

The deterministic harness covers a valid token, a one-byte signature mutation, and a token whose declared algorithm is outside the allowlist. The fixture contains only a public verification key; no private signing material is part of the application or build output.

import { jwt } from '@pulse-compute/jwt'
export default async function handler(ctx) {
const verified = await jwt.verify(ctx, jwt.bearer(ctx.req), {
algorithms: ['ES256'],
key: {
type: 'jwk',
key: {
kty: 'EC',
crv: 'P-256',
x: 'YP7UuiVanTHJYet0xjVtaMBJuJI7Yfps5mliLmDyn7Y',
y: 'eQP-EAi4vJmkGunpVii8ZPLxsgwtfp9Rd6PClNRGIpk',
alg: 'ES256',
use: 'sig',
key_ops: ['verify'],
kid: 'g3-key',
},
},
})
return ctx.text(verified.claims.sub + ':' + verified.protectedHeader.alg)
}
import { defineConfig } from '@pulse-compute/pulse'
export default defineConfig((_scope) => ({
pulse: {
entry: 'src/index.ts',
tests: 'tests/pulse.harness.ts',
defaultProfile: 'node-native',
strict: true,
},
'node-native': {
host: 'node',
target: 'native',
outDir: 'dist-node-native',
crypto: {
ES256: { realization: 'guest-linked:pulse-es256-rustcrypto-p256' },
},
dev: { host: '127.0.0.1', port: 8787, networkFetch: false },
},
}))

Generated from the executable test harness below; these are tested requests or event frames, not an exhaustive application specification. Expected errors and emitted events are included; fixtures and provider setup remain in the harness.

RequestExpected response
valid ES256 bearer
GET /verify
Headers: [["authorization","Bearer eyJ0eXAiOiJKV1QiLCJraWQiOiJnMy1rZXkiLCJhbGciOiJFUzI1NiJ9.eyJzdWIiOiJnMy1zZW5zaXRpdmUtc3ViamVjdCIsImlhdCI6MTk5OTk5OTk5MCwiZXhwIjoyMDAwMDAwMDYwLCJyb2xlcyI6WyJtZW1iZXIiXX0.LgxFHy8spsAvPR5FgmnHS1MnVWEr7rAOVtS-PMSrwnabWfD3tEmOam2km7ZCLiX2l2a_0ycVMIy6VMk95_ZOkQ"]]
{"status":200,"text":"g3-sensitive-subject:ES256"}
wrong ES256 signature
GET /verify
Headers: [["authorization","Bearer eyJ0eXAiOiJKV1QiLCJraWQiOiJnMy1rZXkiLCJhbGciOiJFUzI1NiJ9.eyJzdWIiOiJnMy1zZW5zaXRpdmUtc3ViamVjdCIsImlhdCI6MTk5OTk5OTk5MCwiZXhwIjoyMDAwMDAwMDYwLCJyb2xlcyI6WyJtZW1iZXIiXX0.rgxFHy8spsAvPR5FgmnHS1MnVWEr7rAOVtS-PMSrwnabWfD3tEmOam2km7ZCLiX2l2a_0ycVMIy6VMk95_ZOkQ"]]
{"error":{"name":"JwtError","code":"PULSE_JWT_SIGNATURE_INVALID"}}
disallowed algorithm
GET /verify
Headers: [["authorization","Bearer eyJ0eXAiOiJKV1QiLCJraWQiOiJnMy1rZXkiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJnMy1zZW5zaXRpdmUtc3ViamVjdCIsImlhdCI6MTk5OTk5OTk5MCwiZXhwIjoyMDAwMDAwMDYwLCJyb2xlcyI6WyJtZW1iZXIiXX0.LgxFHy8spsAvPR5FgmnHS1MnVWEr7rAOVtS-PMSrwnabWfD3tEmOam2km7ZCLiX2l2a_0ycVMIy6VMk95_ZOkQ"]]
{"error":{"name":"JwtError","code":"PULSE_JWT_ALGORITHM_NOT_ALLOWED"}}

The selected profile is node-native; this checked excerpt identifies its target, provider and recognized capabilities. Paths, hashes and additional inspection fields are omitted.

Terminal window
npm run inspect -- --json
{
"status": "ok",
"project": {
"target": "native"
},
"provider": {
"id": "node"
},
"compiler": {
"capabilities": [
"jwt.verify",
"response.text"
]
}
}

Check this project and its local toolchain before execution. This selected result is verified by the documentation gate; another machine may report different prerequisite checks.

Terminal window
npm run doctor -- --json
{
"status": "passed",
"summary": {
"warnings": 0,
"failed": 0
}
}

Build once into a separate directory, then replay the retained artifact without running or rebuilding the application. This checked excerpt accounts for registered handlers in the build evidence; it is not runtime request coverage.

Terminal window
npm run build -- --out .pulse-docs-build
npm exec -- pulse report --artifact .pulse-docs-build/pulse-build.json --json
{
"kind": "pulse.application-report",
"reportVersion": 1,
"analytics": {
"coverage": {
"handlers": {
"expected": null,
"observed": 0,
"reason": "not-recorded",
"status": "unavailable"
}
}
}
}

Optional offline HTML uses the same retained evidence:

Terminal window
npm exec -- pulse report --artifact .pulse-docs-build/pulse-build.json --html

Review reports before sharing. Missing, stale or incompatible evidence is an error; timings, paths and hashes are not presented as stable output.

Interactive report captured from this example at source e69e4b6f1381. Build evidence describes this captured build, not a runtime guarantee.

Open full report · Capture provenance

Terminal window
pulse doctor
pulse inspect
pulse test
pulse dev
pulse build

The documented result below is executed against the exact linked Native artifact by the documentation gate.

Terminal window
pulse test --json
{
"status": "passed",
"provider": "node",
"summary": {
"total": 3,
"passed": 3,
"failed": 0
},
"cases": [
{
"name": "valid ES256 bearer",
"status": "passed",
"response": {
"status": 200
}
},
{
"name": "wrong ES256 signature",
"status": "passed",
"expectedError": {
"code": "PULSE_JWT_SIGNATURE_INVALID"
}
},
{
"name": "disallowed algorithm",
"status": "passed",
"expectedError": {
"code": "PULSE_JWT_ALGORITHM_NOT_ALLOWED"
}
}
]
}
const valid =
'eyJ0eXAiOiJKV1QiLCJraWQiOiJnMy1rZXkiLCJhbGciOiJFUzI1NiJ9.' +
'eyJzdWIiOiJnMy1zZW5zaXRpdmUtc3ViamVjdCIsImlhdCI6MTk5OTk5OTk5MCwi' +
'ZXhwIjoyMDAwMDAwMDYwLCJyb2xlcyI6WyJtZW1iZXIiXX0.' +
'LgxFHy8spsAvPR5FgmnHS1MnVWEr7rAOVtS-PMSrwnabWfD3tEmOam2km7ZCLiX2' +
'l2a_0ycVMIy6VMk95_ZOkQ'
const wrongSignature =
'eyJ0eXAiOiJKV1QiLCJraWQiOiJnMy1rZXkiLCJhbGciOiJFUzI1NiJ9.' +
'eyJzdWIiOiJnMy1zZW5zaXRpdmUtc3ViamVjdCIsImlhdCI6MTk5OTk5OTk5MCwi' +
'ZXhwIjoyMDAwMDAwMDYwLCJyb2xlcyI6WyJtZW1iZXIiXX0.' +
'rgxFHy8spsAvPR5FgmnHS1MnVWEr7rAOVtS-PMSrwnabWfD3tEmOam2km7ZCLiX2' +
'l2a_0ycVMIy6VMk95_ZOkQ'
const disallowedAlgorithm =
'eyJ0eXAiOiJKV1QiLCJraWQiOiJnMy1rZXkiLCJhbGciOiJIUzI1NiJ9.' +
'eyJzdWIiOiJnMy1zZW5zaXRpdmUtc3ViamVjdCIsImlhdCI6MTk5OTk5OTk5MCwi' +
'ZXhwIjoyMDAwMDAwMDYwLCJyb2xlcyI6WyJtZW1iZXIiXX0.' +
'LgxFHy8spsAvPR5FgmnHS1MnVWEr7rAOVtS-PMSrwnabWfD3tEmOam2km7ZCLiX2' +
'l2a_0ycVMIy6VMk95_ZOkQ'
function authorization(token: string) {
return { authorization: `Bearer ${token}` }
}
export default { cases: [
{
name: 'valid ES256 bearer',
request: { method: 'GET', path: '/verify', headers: authorization(valid) },
expect: { status: 200, text: 'g3-sensitive-subject:ES256' },
},
{
name: 'wrong ES256 signature',
request: {
method: 'GET',
path: '/verify',
headers: authorization(wrongSignature),
},
expect: {
error: { name: 'JwtError', code: 'PULSE_JWT_SIGNATURE_INVALID' },
},
},
{
name: 'disallowed algorithm',
request: {
method: 'GET',
path: '/verify',
headers: authorization(disallowedAlgorithm),
},
expect: {
error: { name: 'JwtError', code: 'PULSE_JWT_ALGORITHM_NOT_ALLOWED' },
},
},
] }

See JWT for the full verification policy and supported key sources.

For build settings, see Native build optimization.

ArtifactDefault build
Application input2.8 KiB (2,848 bytes)
Shared ES256/RS256 guest input35.5 KiB (36,378 bytes)
Final linked canonical-native.wasm35.1 KiB (35,926 bytes)

The executable documentation gate rebuilds and measures the default artifact. Measured with Node 24.18.0 and lockfile-pinned AssemblyScript 0.28.18. These are uncompressed on-disk sizes, not transfer sizes or platform limits. The first two rows are the exact primary and guest inputs recorded by guest-link-report.json; the last row is the validated output of the deterministic static link and audited post-link optimization. Linked output is not the arithmetic sum of its inputs because the linker composes and deduplicates the modules.