Skip to content

Commit 569c465

Browse files
committed
docs(pq-key-fingerprint/ts): phase 3 - add package documentation (ENG-1762)
1 parent e370a25 commit 569c465

1 file changed

Lines changed: 90 additions & 2 deletions

File tree

packages/pq-key-fingerprint/ts/README.md

Lines changed: 90 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,99 @@ npm install pq-key-fingerprint
1111
## Usage
1212

1313
```typescript
14-
import { } from 'pq-key-fingerprint';
14+
import {
15+
FingerprintError,
16+
fingerprintJWK,
17+
fingerprintPEM,
18+
fingerprintPublicKey,
19+
fingerprintPublicKeyBytes,
20+
fingerprintSPKI,
21+
} from 'pq-key-fingerprint';
1522

16-
// Coming soon
23+
const mlKem512PublicKey = new Uint8Array(800);
24+
25+
// 1) Raw bytes + algorithm
26+
const fromBytes = await fingerprintPublicKeyBytes(mlKem512PublicKey, 'ML-KEM-512');
27+
console.log(fromBytes); // hex string (default)
28+
29+
// 2) KeyData-like input
30+
const fromPublicKeyObject = await fingerprintPublicKey({
31+
alg: 'ML-KEM-512',
32+
type: 'public',
33+
bytes: mlKem512PublicKey,
34+
});
35+
36+
// 3) SPKI DER bytes
37+
const spkiDer = new Uint8Array(/* SPKI DER bytes */);
38+
const fromSpki = await fingerprintSPKI(spkiDer);
39+
40+
// 4) PEM
41+
const pem = `-----BEGIN PUBLIC KEY-----
42+
...
43+
-----END PUBLIC KEY-----`;
44+
const fromPem = await fingerprintPEM(pem);
45+
46+
// 5) JWK
47+
const jwk = {
48+
kty: 'PQC' as const,
49+
alg: 'ML-KEM-512' as const,
50+
x: 'base64url-encoded-public-key-bytes',
51+
};
52+
const fromJwk = await fingerprintJWK(jwk);
53+
54+
// Digest and encoding options
55+
const sha512Base64Url = await fingerprintPublicKeyBytes(mlKem512PublicKey, 'ML-KEM-512', {
56+
digest: 'SHA-512',
57+
encoding: 'base64url',
58+
});
59+
60+
const rawDigestBytes = await fingerprintPublicKeyBytes(mlKem512PublicKey, 'ML-KEM-512', {
61+
digest: 'SHA-384',
62+
encoding: 'bytes',
63+
});
64+
65+
console.log(sha512Base64Url, rawDigestBytes.length);
66+
67+
// Error handling
68+
try {
69+
await fingerprintPEM('not-a-valid-pem');
70+
} catch (error) {
71+
if (error instanceof FingerprintError) {
72+
console.error('Fingerprint failed:', error.message);
73+
} else {
74+
throw error;
75+
}
76+
}
1777
```
1878

79+
## API
80+
81+
```typescript
82+
type FingerprintDigest = 'SHA-256' | 'SHA-384' | 'SHA-512';
83+
type FingerprintEncoding = 'hex' | 'base64' | 'base64url' | 'bytes';
84+
85+
interface FingerprintOptions {
86+
digest?: FingerprintDigest;
87+
encoding?: FingerprintEncoding;
88+
}
89+
90+
type FingerprintResult = string | Uint8Array;
91+
92+
function fingerprintPublicKey(input: PublicKeyInput, options?: FingerprintOptions): Promise<FingerprintResult>;
93+
function fingerprintPublicKeyBytes(
94+
bytes: Uint8Array,
95+
alg: AlgorithmName,
96+
options?: FingerprintOptions,
97+
): Promise<FingerprintResult>;
98+
function fingerprintSPKI(spki: Uint8Array, options?: FingerprintOptions): Promise<FingerprintResult>;
99+
function fingerprintPEM(pem: string, options?: FingerprintOptions): Promise<FingerprintResult>;
100+
function fingerprintJWK(jwk: PQJwk, options?: FingerprintOptions): Promise<FingerprintResult>;
101+
```
102+
103+
## Compatibility Note
104+
105+
All exported fingerprint entrypoints enforce a strict local error boundary by design. Upstream parser/validation failures from `pq-key-encoder` are translated into `pq-key-fingerprint` error classes (subclasses of `FingerprintError`) before they leave this package. This behavior is intentional and part of the package contract.
106+
19107
## License
20108

21109
MIT

0 commit comments

Comments
 (0)