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
60 changes: 57 additions & 3 deletions packages/pq-algorithm-id/ts/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# pq-algorithm-id

Algorithm identifier mappings (JOSE, COSE, X.509)
Canonical post-quantum algorithm identifier mappings across `name`, `oid`, `jose`, `cose`, and `x509` descriptor shapes.

Package boundary:

- `pq-oid`: low-level OID primitives (constants, OID encode/decode)
- `pq-algorithm-id`: multi-identifier mapping and normalization API

## Installation

Expand All @@ -11,11 +16,60 @@ npm install pq-algorithm-id
## Usage

```typescript
import { } from 'pq-algorithm-id';
import {
fromCose,
fromJose,
fromOid,
fromX509AlgorithmIdentifier,
toCose,
toJose,
toOid,
toX509AlgorithmIdentifier,
} from 'pq-algorithm-id';

// Name/OID lookup
toOid('ML-DSA-65'); // '2.16.840.1.101.3.4.3.18'
fromOid('2.16.840.1.101.3.4.3.18'); // 'ML-DSA-65'

// JOSE/COSE mapping (currently ML-DSA only)
toJose('ML-DSA-65'); // 'ML-DSA-65'
fromJose('ML-DSA-65'); // 'ML-DSA-65'
toCose('ML-DSA-65'); // -49
fromCose(-49); // 'ML-DSA-65'

// X.509 descriptor mapping
toX509AlgorithmIdentifier('ML-KEM-768');
// {
// oid: '2.16.840.1.101.3.4.4.2',
// parameters: { kind: 'absent' }
// }

// Coming soon
fromX509AlgorithmIdentifier({
oid: '2.16.840.1.101.3.4.3.18',
parameters: null,
});
// {
// oid: '2.16.840.1.101.3.4.3.18',
// parameters: { kind: 'null' }
// }
```

## Behavior Notes

- `fromOid`, `fromJose`, and `fromCose` are strict lookups (no trimming, no case normalization).
- `toX509AlgorithmIdentifier(name)` emits `parameters: { kind: 'absent' }` by default.
- `fromX509AlgorithmIdentifier(input)` accepts `parameters` as `undefined`, `null`, `{ kind: 'absent' }`, or `{ kind: 'null' }`.
- Unsupported mappings (for example `toJose('ML-KEM-512')`) throw typed errors.

## Adoption Order

Suggested downstream migration order:

1. `pq-key-encoder`
2. `pq-cose`
3. `pq-jws`
4. `pq-jwk`

## License

MIT
18 changes: 17 additions & 1 deletion packages/pq-oid/ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ npm install pq-oid
bun add pq-oid
```

## Migration Note

`pq-oid` remains the low-level OID primitive package. For canonical multi-identifier mapping (`name`/`oid`/`jose`/`cose`/`x509`), use `pq-algorithm-id`.

The JOSE/COSE helpers in `pq-oid` are still available for compatibility and are now deprecated in favor of `pq-algorithm-id`.

## Usage

```typescript
Expand All @@ -43,7 +49,7 @@ OID.toName('2.16.840.1.101.3.4.3.18') // 'ML-DSA-65'
OID.toBytes('2.16.840.1.101.3.4.4.1') // Uint8Array
OID.fromBytes(bytes) // '2.16.840.1.101.3.4.4.1'

// JOSE/COSE mappings (ML-DSA only)
// JOSE/COSE mappings (ML-DSA only, compatibility path)
OID.toJOSE('ML-DSA-65') // 'ML-DSA-65'
OID.toCOSE('ML-DSA-65') // -48
OID.fromJOSE('ML-DSA-65') // 'ML-DSA-65'
Expand All @@ -68,6 +74,16 @@ Algorithm.listByType('sign') // ML-DSA + SLH-DSA variants
Algorithm.listByFamily('ML-DSA') // ['ML-DSA-44', 'ML-DSA-65', 'ML-DSA-87']
```

For new identifier mapping code:

```typescript
import { fromJose, toCose, toOid } from 'pq-algorithm-id';

toOid('ML-DSA-65'); // '2.16.840.1.101.3.4.3.18'
fromJose('ML-DSA-65'); // 'ML-DSA-65'
toCose('ML-DSA-65'); // -49
```

## Supported Algorithms

### ML-KEM (FIPS 203) — Key Encapsulation
Comment thread
eacet marked this conversation as resolved.
Expand Down
20 changes: 18 additions & 2 deletions packages/pq-oid/ts/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Main exports for pq-oid package

import { decodeOid, encodeOid } from './encoding';
import { fromCOSE, toCOSE } from './mappings/cose';
import { fromJOSE, toJOSE } from './mappings/jose';
import { fromCOSE as fromCOSEMapping, toCOSE as toCOSEMapping } from './mappings/cose';
import { fromJOSE as fromJOSEMapping, toJOSE as toJOSEMapping } from './mappings/jose';
import {
// Lookup functions
fromName,
Expand Down Expand Up @@ -37,6 +37,18 @@ export { SlhDsa } from './slh-dsa';
// Re-export all types
export * from './types';

/** @deprecated Use toJose() from 'pq-algorithm-id'. */
export const toJOSE = toJOSEMapping;

/** @deprecated Use fromJose() from 'pq-algorithm-id'. */
export const fromJOSE = fromJOSEMapping;

/** @deprecated Use toCose() from 'pq-algorithm-id'. */
export const toCOSE = toCOSEMapping;

/** @deprecated Use fromCose() from 'pq-algorithm-id'. */
export const fromCOSE = fromCOSEMapping;

// Unified OID object with all constants and functions
export const OID = {
// ML-KEM OID constants
Expand Down Expand Up @@ -74,10 +86,14 @@ export const OID = {
fromBytes: decodeOid,

// JOSE mapping functions
/** @deprecated Use toJose() from 'pq-algorithm-id'. */
toJOSE,
/** @deprecated Use fromJose() from 'pq-algorithm-id'. */
fromJOSE,

// COSE mapping functions
/** @deprecated Use toCose() from 'pq-algorithm-id'. */
toCOSE,
/** @deprecated Use fromCose() from 'pq-algorithm-id'. */
fromCOSE,
};
Loading