> For the complete documentation index, see [llms.txt](https://docs.openbotauth.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.openbotauth.org/crawlers/registry-signer.md).

# registry-signer Package

A TypeScript/JavaScript library for generating Ed25519 key pairs and formatting them as JSON Web Keys (JWK) for use with OpenBotRegistry.

## Installation

```bash
npm install @openbotauth/registry-signer
```

## Quick Start

```typescript
import {
  generateEd25519KeyPair,
  publicKeyToJwk,
  privateKeyToJwk,
  createJwks
} from '@openbotauth/registry-signer';

// Generate a new Ed25519 key pair
const keyPair = await generateEd25519KeyPair();

// Export public key as JWK (for registration)
const publicJwk = await publicKeyToJwk(keyPair.publicKey, 'my-key-id');

// Export private key as JWK (for signing - keep secure!)
const privateJwk = await privateKeyToJwk(keyPair.privateKey, 'my-key-id');

// Create a JWKS containing your public key
const jwks = await createJwks([publicJwk]);
console.log(JSON.stringify(jwks, null, 2));
```

## API Reference

### Key Generation

#### `generateEd25519KeyPair()`

Generates a new Ed25519 key pair using the Web Crypto API.

```typescript
const keyPair = await generateEd25519KeyPair();
// Returns: CryptoKeyPair { publicKey, privateKey }
```

### JWK Conversion

#### `publicKeyToJwk(publicKey, keyId?)`

Converts a CryptoKey public key to JWK format.

```typescript
const jwk = await publicKeyToJwk(keyPair.publicKey, 'optional-key-id');
// Returns:
// {
//   kty: 'OKP',
//   crv: 'Ed25519',
//   x: 'base64url-encoded-public-key',
//   kid: 'optional-key-id'
// }
```

#### `privateKeyToJwk(privateKey, keyId?)`

Converts a CryptoKey private key to JWK format.

```typescript
const jwk = await privateKeyToJwk(keyPair.privateKey, 'optional-key-id');
// Returns:
// {
//   kty: 'OKP',
//   crv: 'Ed25519',
//   x: 'base64url-encoded-public-key',
//   d: 'base64url-encoded-private-key',
//   kid: 'optional-key-id'
// }
```

### JWKS Creation

#### `createJwks(keys)`

Creates a JSON Web Key Set from an array of JWKs.

```typescript
const jwks = await createJwks([publicJwk]);
// Returns:
// {
//   keys: [
//     { kty: 'OKP', crv: 'Ed25519', x: '...', kid: '...' }
//   ]
// }
```

### Base64 Utilities

#### `base64UrlEncode(data)`

Encodes a Uint8Array to base64url format (no padding).

```typescript
const encoded = base64UrlEncode(new Uint8Array([1, 2, 3]));
```

#### `base64UrlDecode(str)`

Decodes a base64url string to Uint8Array.

```typescript
const decoded = base64UrlDecode('AQID');
```

## Hosting Your JWKS

Once you've generated your key pair, host the JWKS at a publicly accessible URL:

### Option 1: Static File

Save the JWKS output to a file and serve it:

```bash
# Generate and save JWKS
node -e "
const { generateEd25519KeyPair, publicKeyToJwk, createJwks } = require('@openbotauth/registry-signer');
(async () => {
  const keyPair = await generateEd25519KeyPair();
  const jwk = await publicKeyToJwk(keyPair.publicKey, 'key-1');
  const jwks = await createJwks([jwk]);
  console.log(JSON.stringify(jwks, null, 2));
})();
" > .well-known/jwks.json
```

### Option 2: Dynamic Endpoint

Serve the JWKS from your application:

```typescript
// Express.js example
app.get('/.well-known/jwks.json', (req, res) => {
  res.json({
    keys: [
      {
        kty: 'OKP',
        crv: 'Ed25519',
        x: process.env.PUBLIC_KEY_X,
        kid: 'crawler-key-1'
      }
    ]
  });
});
```

## Security Considerations

* **Never expose your private key** - The private key (`d` parameter) should never be shared or included in your JWKS
* **Store private keys securely** - Use environment variables, secret managers, or hardware security modules
* **Use unique key IDs** - Include a `kid` to identify keys during rotation
* **Rotate keys periodically** - Generate new keys and update your registration

## TypeScript Support

Full TypeScript definitions are included. The package exports proper types for all functions and return values.

## Browser Compatibility

This package uses the Web Crypto API and works in:

* Node.js 18+
* Modern browsers (Chrome, Firefox, Safari, Edge)
* Deno
* Cloudflare Workers

## Source Code

GitHub: [OpenBotAuth/openbotauth](https://github.com/OpenBotAuth/openbotauth/tree/main/packages/registry-signer)

npm: [@openbotauth/registry-signer](https://www.npmjs.com/package/@openbotauth/registry-signer)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.openbotauth.org/crawlers/registry-signer.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
