# Code Deb Webhook Kit SDK

**Target release:** `@codedeb/webhook-kit@0.1.0` passed isolated ESM installation and TypeScript consumer checks; public npm availability has not yet been independently verified.

Node.js Standard Webhooks HMAC-SHA256 signing and verification with key rotation and durable replay integration.

## Build and inspect the candidate

From the CodeDeb repository root:

```bash
npm ci
npm run test:nepal-sdks
npm run sdk:pack:verify
node scripts/sdk/stage-npm-package.mjs sdk-webhook-kit
```

The staged npm artifact is placed at `.sdk-artifacts/npm-stage/sdk-webhook-kit`. The source package remains `private: true`; only explicitly verified staged artifacts can be published.

After a verified public release, the intended npm command will be `npm install @codedeb/webhook-kit`. This command is **not yet a public-install guarantee**.

## Quickstart — actual source exports

```typescript
import {createWebhookSecret,signWebhook,verifyWebhook} from '@codedeb/webhook-kit';
const secret=createWebhookSecret();
const headers=signWebhook({secret,id:'msg_abcdef12',timestamp:1000,body:'{}'});
console.log(verifyWebhook({headers,body:'{}',secrets:[secret],now:1000}));
```

These imports describe the planned npm entrypoints. The bundled JavaScript and TypeScript exports are exercised in an isolated consumer during the candidate release gate.

## API reference

| Export | Purpose |
| --- | --- |
| `createWebhookSecret` | Generate 32 random secret bytes with the whsec_ convention. |
| `signWebhook / verifyWebhook` | HMAC SHA-256 over id.timestamp.rawPayload; verify constant-time against rotated keys. |
| `acceptWebhookOnce` | Invoke caller-supplied atomic replay-claim storage after signature verification. |
| `shouldRetryWebhook / webhookRetryDelay / retryAfterDelay` | Bounded Retry-After and exponential delivery scheduling. |

## Production integration and limitations

Node 20+ only; never bundle webhook signing secrets in a browser. A durable queue and atomic replay store are not provided. Callers should respond 2xx only after durable event acceptance; this does not guarantee exactly-once processing. No Ed25519 support in this release.

## Versioning and attribution

- **0.1.0 — candidate (2026-11-21):** Initial independent ESM package and TypeScript declarations, subject to runtime, type, security and publication checks.
- **License:** Apache-2.0 for Code Deb-authored package code. The full license text is attached only to the reviewed public tarball. Code Deb brand names and logos are not licensed as trademarks.
- **Documentation:** [API reference](/docs/sdk/webhook-kit) · [All SDKs](/docs/sdk) · [Developer resources](/docs/resources)
- **Related research:** [Source](https://github.com/standard-webhooks/standard-webhooks/blob/main/spec/standard-webhooks.md) · [Source](https://www.svix.com/guides/receiving/receive-webhooks-with-javascript-nodejs/)

No hosted service, support SLA or official Nepal government certification is implied by the package.

## Implementation workflow

1. Sign and verify the exact raw payload bytes including message ID and timestamp.
2. Use constant-time HMAC comparison against limited rotated secrets.
3. Claim event IDs in durable atomic replay storage only after verification.
4. Handle Retry-After and bounded backoff in the delivery queue without claiming exactly-once processing.

## Registry verification and installation

```bash
npm view @codedeb/webhook-kit@0.1.0 version
# Install when the target release is listed and its tarball is retrievable:
npm install @codedeb/webhook-kit@0.1.0
```

A valid local package is not automatically a live npm release. A verified publication must expose version metadata, a current dist-tag and a public tarball. Keep installation versions pinned and check the included distribution license.

## Production acceptance criteria

- Verify normal, corrupted, missing and boundary inputs with the actual package exports.
- Keep any secrets, authorization and persistent state in application-owned server adapters.
- Record explicit classifications, retry outcomes or regression evidence without turning unknown into verified.
- Audit access limits, failure handling and operational monitoring independently of the SDK.

## Troubleshooting

**Registry 404:** Confirm the intended version on [npm](https://www.npmjs.com/package/@codedeb/webhook-kit), and do not assume publication from local test output. **Unexpected classification or diff:** Review the original evidence fields and source data. **External processing problem:** Inspect your event store, browser runner, authenticated client or queue; the SDK is a library, not a hosted processing service.

## Related SDKs

[log redact](/docs/sdk/log-redact) · [sdk core](/docs/sdk/sdk-core) · [Developer SDKs](/docs/sdk) · [Technical resources](/docs/resources)
