Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,43 @@ jobs:

- name: Build package
run: npm run build

deno:
runs-on: ubuntu-latest
timeout-minutes: 10

# Deno is a supported runtime: Supabase Edge Functions load the package as
# npm:@proofage/node, and customers integrate from there. scripts/deno-smoke.sh
# packs the SDK and runs deno/smoke.ts against the tarball (HMAC vectors, a
# signed create, the webhook handler).
#
# 2.1.4 the Deno that Supabase Edge Runtime 1.77-1.79 reported in production
# User-Agents (Nov 2026); raise it when Supabase moves on
# v2.x the current Deno 2 release
strategy:
fail-fast: false
matrix:
deno-version: ['2.1.4', 'v2.x']

name: Deno ${{ matrix.deno-version }}

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 24
cache: npm

- name: Install dependencies
run: npm ci

- name: Setup Deno
uses: denoland/setup-deno@v2
with:
deno-version: ${{ matrix.deno-version }}

- name: Deno smoke test
run: scripts/deno-smoke.sh
9 changes: 9 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,12 @@ does not ship (see `files` in package.json), so maintainer notes belong here.
`proofage/php-sdk` — the file the app also runs through its real `VerifyHmacSignature`
middleware. Refresh it by copying when that file changes; never edit it by hand. A signing
change here that breaks a vector breaks real requests.

## Deno

Deno 2 (and Supabase Edge Functions, which import `npm:@proofage/node`) is a supported runtime.
CI's `deno` job runs `scripts/deno-smoke.sh`: it packs the package and runs `deno/smoke.ts`
against the tarball. Keep the SDK to what Deno's Node compatibility provides (`node:crypto`,
`Buffer`, `process.env`, global `fetch`); anything else fails that job. Without a local Deno, run
the smoke test in Docker after building, packing and installing the tarball into `deno/`:
`docker run --rm -v "$PWD":/repo -w /repo/deno denoland/deno:2.1.4 run --allow-net=127.0.0.1 --allow-env --allow-read smoke.ts`.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,25 @@ This package provides a first-class Node.js integration: auto-configuration from

## Requirements

- Node.js 22+ (see `engines` in package.json)
- Node.js 22+ (see `engines` in package.json), or Deno 2, including Supabase Edge Functions

## Installation

```bash
npm install @proofage/node
```

On Deno and in Supabase Edge Functions, import it with the `npm:` specifier; there is nothing to install:

```ts
import { ProofAgeClient } from 'npm:@proofage/node';

const client = new ProofAgeClient({
apiKey: Deno.env.get('PROOFAGE_API_KEY'),
secretKey: Deno.env.get('PROOFAGE_SECRET_KEY'),
});
```

## Quick Start

Set your environment variables:
Expand Down
5 changes: 5 additions & 0 deletions deno/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"private": true,
"type": "module",
"description": "Deno smoke test for the packed @proofage/node tarball. scripts/deno-smoke.sh installs the tarball here and runs smoke.ts."
}
140 changes: 140 additions & 0 deletions deno/smoke.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/**
* Runs the packed @proofage/node under Deno, the way a Supabase Edge Function loads it:
* as npm package code, not as source. It checks what the SDK needs from the runtime —
* node:crypto, Buffer, process.env and fetch — on real calls:
*
* 1. the shared HMAC vectors (the server accepts these exact signatures);
* 2. a signed create against a local stand-in for the API, keys from the environment
* and passed explicitly, with the SDK identification header;
* 3. webhookHandler accepting a signed delivery and refusing a tampered one.
*
* Run by scripts/deno-smoke.sh; it is not part of the npm package.
*/
import {
generateHmacSignature,
generateWebhookSignature,
ProofAgeClient,
SDK_VERSION,
webhookHandler,
} from '@proofage/node';

function check(condition: unknown, message: string): asserts condition {
if (!condition) {
throw new Error(`Deno smoke test failed: ${message}`);
}
}

const API_KEY = 'pk_test_deno_smoke';
const SECRET_KEY = 'sk_test_deno_smoke';

// 1. Shared HMAC vectors.
interface Vectors {
secret: string;
json: Array<{ name: string; method: string; path: string; query?: string; body: string; expected: string }>;
}

const vectors = JSON.parse(
await Deno.readTextFile(new URL('../tests/fixtures/hmac-vectors.json', import.meta.url)),
) as Vectors;

let checkedVectors = 0;
for (const vector of vectors.json) {
if (vector.query) {
continue; // the vitest suite covers query normalisation; the crypto is the same call
}
const [, version, ...rest] = vector.path.split('/');
const signature = generateHmacSignature(vectors.secret, vector.method, version!, rest.join('/'), vector.body);
check(signature === vector.expected, `HMAC vector "${vector.name}"`);
checkedVectors++;
}
check(checkedVectors > 0, 'no HMAC vector was checked');

// 2. A signed create against a local stand-in for the API.
const seen: Array<{ apiKey: string | null; sdk: string | null; signatureValid: boolean }> = [];

const server = Deno.serve({ hostname: '127.0.0.1', port: 0, onListen: () => {} }, async (request) => {
const url = new URL(request.url);
const body = await request.text();
const [, version, ...rest] = url.pathname.split('/');
const expected = generateHmacSignature(SECRET_KEY, request.method, version!, rest.join('/'), body);

seen.push({
apiKey: request.headers.get('x-api-key'),
sdk: request.headers.get('x-proofage-sdk'),
signatureValid: request.headers.get('x-hmac-signature') === expected,
});

if (request.method !== 'POST' || url.pathname !== '/v1/verifications') {
return new Response(JSON.stringify({ message: 'Not found' }), { status: 404 });
}

const payload = JSON.parse(body) as { external_id: string };

return Response.json(
{
id: '550e8400-e29b-41d4-a716-446655440000',
external_id: payload.external_id,
status: 'created',
url: 'https://idv.proofage.net/q/AB12cd34Ef',
},
{ status: 201, headers: { Date: new Date().toUTCString() } },
);
});

const baseUrl = `http://127.0.0.1:${server.addr.port}`;

try {
// Keys passed explicitly, as the docs show for Deno.
const explicit = new ProofAgeClient({ apiKey: API_KEY, secretKey: SECRET_KEY, baseUrl });
const created = await explicit.verifications().create({ external_id: 'user_1' });
check(created?.url === 'https://idv.proofage.net/q/AB12cd34Ef', 'create returned the verification url');

// Keys read from the environment, as on Node.
Deno.env.set('PROOFAGE_API_KEY', API_KEY);
Deno.env.set('PROOFAGE_SECRET_KEY', SECRET_KEY);
Deno.env.set('PROOFAGE_BASE_URL', `${baseUrl}/v1`); // a trailing /v1 is accepted
const fromEnv = new ProofAgeClient();
const createdFromEnv = await fromEnv.verifications().create({ external_id: 'user_2' });
check(createdFromEnv?.external_id === 'user_2', 'create with keys from the environment');

check(seen.length === 2, `expected 2 requests, the stand-in saw ${seen.length}`);
for (const request of seen) {
check(request.apiKey === API_KEY, 'X-API-Key is the public key');
check(request.signatureValid, 'X-HMAC-Signature matches the request');
check(request.sdk?.startsWith(`node/${SDK_VERSION}`), `X-ProofAge-Sdk names node/${SDK_VERSION}`);
}
} finally {
await server.shutdown();
}

// 3. Webhook verification.
const delivery = { event: 'verification.updated', data: { id: '550e8400-e29b-41d4-a716-446655440000', status: 'approved' } };
const timestamp = Math.floor(Date.now() / 1000);
const deliverySignature = generateWebhookSignature(delivery, SECRET_KEY, timestamp);

const received: unknown[] = [];
const handler = webhookHandler((payload) => {
received.push(payload);
}, { apiKey: API_KEY, secretKey: SECRET_KEY });

const webhookRequest = (signature: string) =>
new Request('http://localhost/webhooks/proofage', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Auth-Client': API_KEY,
'X-HMAC-Signature': signature,
'X-Timestamp': String(timestamp),
},
body: JSON.stringify(delivery),
});

const accepted = await handler(webhookRequest(deliverySignature));
check(accepted.status === 200, `a signed webhook is accepted (got ${accepted.status})`);
check(received.length === 1, 'the handler received the payload');

const refused = await handler(webhookRequest('0'.repeat(64)));
check(refused.status === 401, `a tampered webhook is refused (got ${refused.status})`);
check(received.length === 1, 'the handler did not run for a tampered webhook');

console.log(`@proofage/node ${SDK_VERSION} works on Deno ${Deno.version.deno}: ${checkedVectors} HMAC vectors, signed create, webhook handler.`);
18 changes: 18 additions & 0 deletions scripts/deno-smoke.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash
# Packs the SDK and runs deno/smoke.ts against the tarball, the way a Deno or Supabase
# Edge Function project loads it (npm package code from node_modules, not the sources).
# Needs node/npm (to build and pack) and deno on PATH. Usage: scripts/deno-smoke.sh
set -euo pipefail

root="$(cd "$(dirname "$0")/.." && pwd)"
cd "$root"

npm run build >/dev/null
tarball="$root/$(npm pack --silent | tail -n 1)"
trap 'rm -f "$tarball"; rm -rf "$root/deno/node_modules"' EXIT

(cd deno && npm install --no-save --no-package-lock --silent "$tarball")

# Run from deno/ so Deno resolves @proofage/node from deno/node_modules, not the repo itself.
cd deno
deno run --allow-net=127.0.0.1 --allow-env --allow-read --no-prompt smoke.ts
Loading