@sebastienrousseau/crypto-sdk 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +114 -58
- package/dist/errors.d.ts +8 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +32 -0
- package/dist/index.d.ts +54 -234
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +50 -119
- package/dist/key-types.d.ts +83 -0
- package/dist/key-types.d.ts.map +1 -0
- package/dist/key-types.js +3 -0
- package/dist/negotiation.d.ts +3 -0
- package/dist/negotiation.d.ts.map +1 -0
- package/dist/negotiation.js +105 -0
- package/dist/types.d.ts +132 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/package.json +16 -12
package/README.md
CHANGED
|
@@ -80,34 +80,71 @@ import { CryptoClient } from "@sebastienrousseau/crypto-sdk";
|
|
|
80
80
|
|
|
81
81
|
const client = new CryptoClient({
|
|
82
82
|
baseUrl: "http://localhost:3000",
|
|
83
|
+
apiKey: "<the server's CRYPTO_API_KEY>",
|
|
83
84
|
});
|
|
84
85
|
|
|
85
86
|
const { data } = await client.hash({ algorithm: "sha256", data: "hello" });
|
|
86
87
|
console.log(data.digest);
|
|
87
88
|
```
|
|
88
89
|
|
|
89
|
-
`CryptoClient` accepts two
|
|
90
|
+
`CryptoClient` accepts two authentication mechanisms. The server refuses
|
|
91
|
+
unauthenticated requests unless it runs with `ALLOW_ANONYMOUS=1`, and each
|
|
92
|
+
route needs a scope (`crypto:sign`, `crypto:keys`, ...); an API key holds
|
|
93
|
+
`crypto:admin`, which covers every scope except `crypto:keys:export`.
|
|
90
94
|
|
|
91
95
|
| Option | Header sent | Description |
|
|
92
96
|
| :------- | :------------------------------ | :--------------- |
|
|
93
97
|
| `apiKey` | `x-api-key: <value>` | Static API key |
|
|
94
98
|
| `token` | `Authorization: Bearer <value>` | JWT bearer token |
|
|
95
99
|
|
|
96
|
-
|
|
100
|
+
### Server-held keys
|
|
101
|
+
|
|
102
|
+
Private keys never cross the API. Key-generation methods return a `keyId`
|
|
103
|
+
with the public key, and the server keeps the private key; methods that
|
|
104
|
+
need it take the `keyId`. A key is usable only by the principal that
|
|
105
|
+
generated it.
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
const { data: key } = await client.generateKeyPair({ algorithm: "ed25519" });
|
|
109
|
+
const { data: sig } = await client.sign({ keyId: key.keyId, message: "hi" });
|
|
110
|
+
const { data: check } = await client.verify({
|
|
111
|
+
publicKey: key.publicKey,
|
|
112
|
+
message: "hi",
|
|
113
|
+
signature: sig.signature,
|
|
114
|
+
});
|
|
115
|
+
console.log(check.valid); // true
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
`exportKey({ keyId })` returns the private parts, and only to a principal
|
|
119
|
+
whose token grants `crypto:keys:export` explicitly.
|
|
120
|
+
|
|
121
|
+
### Errors
|
|
122
|
+
|
|
123
|
+
Failed requests throw a `CryptoApiError` whose `body` is the server's
|
|
124
|
+
[RFC 9457](https://www.rfc-editor.org/rfc/rfc9457) problem
|
|
125
|
+
(`application/problem+json`):
|
|
97
126
|
|
|
98
127
|
```ts
|
|
99
128
|
import { CryptoClient, CryptoApiError } from "@sebastienrousseau/crypto-sdk";
|
|
100
129
|
|
|
101
130
|
try {
|
|
102
|
-
await client.
|
|
131
|
+
await client.sign({ keyId: "k_AAAAAAAAAAAAAAAAAAAAAA", message: "x" });
|
|
103
132
|
} catch (err) {
|
|
104
133
|
if (err instanceof CryptoApiError) {
|
|
105
|
-
console.error(err.status); //
|
|
106
|
-
console.error(err.body.
|
|
134
|
+
console.error(err.status); // 404
|
|
135
|
+
console.error(err.body.type); // "urn:crypto-service:problem:key-not-found"
|
|
136
|
+
console.error(err.body.detail); // "Key not found"
|
|
137
|
+
console.error(err.body.code); // "KEY_NOT_FOUND"
|
|
107
138
|
}
|
|
108
139
|
}
|
|
109
140
|
```
|
|
110
141
|
|
|
142
|
+
`body` has `type`, `title`, `status`, `detail` and `instance`, plus
|
|
143
|
+
`code` for crypto-lib and key-store errors and `errors` (`{ field, message }`
|
|
144
|
+
per failed check) for validation failures. A response without a problem
|
|
145
|
+
body (for example from a proxy) becomes an `about:blank` problem for its
|
|
146
|
+
status code.
|
|
147
|
+
|
|
111
148
|
<p align="right"><a href="#contents">Back to Top</a></p>
|
|
112
149
|
|
|
113
150
|
---
|
|
@@ -150,41 +187,54 @@ signature operations.
|
|
|
150
187
|
|
|
151
188
|
## API Reference
|
|
152
189
|
|
|
153
|
-
|
|
154
|
-
`
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
|
159
|
-
|
|
|
160
|
-
| `
|
|
161
|
-
| `
|
|
162
|
-
| `
|
|
163
|
-
| `
|
|
164
|
-
| `
|
|
165
|
-
| `
|
|
166
|
-
| `
|
|
167
|
-
| `
|
|
168
|
-
| `
|
|
169
|
-
| `
|
|
170
|
-
| `
|
|
171
|
-
| `
|
|
172
|
-
| `
|
|
173
|
-
| `
|
|
174
|
-
| `
|
|
175
|
-
| `
|
|
176
|
-
| `
|
|
177
|
-
| `
|
|
178
|
-
| `
|
|
179
|
-
| `
|
|
180
|
-
| `
|
|
181
|
-
| `
|
|
182
|
-
| `
|
|
183
|
-
| `
|
|
184
|
-
| `
|
|
185
|
-
| `
|
|
186
|
-
| `
|
|
187
|
-
| `
|
|
190
|
+
Methods return `Promise<ApiResponse<T>>` where `ApiResponse<T>` is
|
|
191
|
+
`{ data: T }`, except `getCbom()` (the CycloneDX document itself) and
|
|
192
|
+
`health()`. Methods marked _keyId_ use a server-held key; key-generation
|
|
193
|
+
methods return its `keyId` and public key, never the private key.
|
|
194
|
+
|
|
195
|
+
| Method | Endpoint | Description |
|
|
196
|
+
| :----------------------- | :------------------------------- | :--------------------------------------------- |
|
|
197
|
+
| `hash(body)` | `POST /v2/hash` | Compute a cryptographic hash |
|
|
198
|
+
| `encrypt(body)` | `POST /v2/encrypt` | Encrypt with XChaCha20-Poly1305 |
|
|
199
|
+
| `decrypt(body)` | `POST /v2/decrypt` | Decrypt ciphertext |
|
|
200
|
+
| `generateKeyPair(body?)` | `POST /v2/keys/generate` | Generate a server-held key pair |
|
|
201
|
+
| `exportKey(body)` | `POST /v2/keys/export` | Export a key's private parts (_keyId_) |
|
|
202
|
+
| `sign(body)` | `POST /v2/sign` | Sign with Ed25519 (_keyId_) |
|
|
203
|
+
| `verify(body)` | `POST /v2/verify` | Verify an Ed25519 signature |
|
|
204
|
+
| `kdf(body)` | `POST /v2/kdf` | Derive a key |
|
|
205
|
+
| `mac(body)` | `POST /v2/hmac` | Compute an HMAC |
|
|
206
|
+
| `macVerify(body)` | `POST /v2/hmac/verify` | Verify an HMAC |
|
|
207
|
+
| `passwordHash(body)` | `POST /v2/password/hash` | Hash a password with Argon2id |
|
|
208
|
+
| `passwordVerify(body)` | `POST /v2/password/verify` | Verify a password hash |
|
|
209
|
+
| `passwordEncrypt(body)` | `POST /v2/password/encrypt` | Encrypt data with a password |
|
|
210
|
+
| `passwordDecrypt(body)` | `POST /v2/password/decrypt` | Decrypt password-encrypted data |
|
|
211
|
+
| `keyWrap(body)` | `POST /v2/keys/wrap` | Wrap a key |
|
|
212
|
+
| `keyUnwrap(body)` | `POST /v2/keys/unwrap` | Unwrap a wrapped key |
|
|
213
|
+
| `secretboxSeal(body)` | `POST /v2/secretbox/seal` | Seal plaintext with a symmetric key |
|
|
214
|
+
| `secretboxOpen(body)` | `POST /v2/secretbox/open` | Open a sealed secretbox |
|
|
215
|
+
| `sealedboxSeal(body)` | `POST /v2/sealedbox/seal` | Seal plaintext for an X25519 public key |
|
|
216
|
+
| `sealedboxOpen(body)` | `POST /v2/sealedbox/open` | Open a sealed box (_keyId_) |
|
|
217
|
+
| `sealedboxSealPq(body)` | `POST /v2/sealedbox/seal-pq` | Seal plaintext for a hybrid public key pair |
|
|
218
|
+
| `sealedboxOpenPq(body)` | `POST /v2/sealedbox/open-pq` | Open a hybrid sealed box (_keyId_) |
|
|
219
|
+
| `mlKemGenerateKeyPair()` | `POST /v2/pq/keygen` | Generate a server-held ML-KEM-768 key pair |
|
|
220
|
+
| `mlKemEncapsulate(body)` | `POST /v2/pq/encapsulate` | Encapsulate to an ML-KEM-768 public key |
|
|
221
|
+
| `mlKemDecapsulate(body)` | `POST /v2/pq/decapsulate` | Decapsulate (_keyId_) |
|
|
222
|
+
| `pqGenerateKeyPair()` | `POST /v2/pq/hybrid/keygen` | Generate a server-held hybrid key pair |
|
|
223
|
+
| `pqEncapsulate(body)` | `POST /v2/pq/hybrid/encapsulate` | Encapsulate a hybrid shared secret |
|
|
224
|
+
| `pqDecapsulate(body)` | `POST /v2/pq/hybrid/decapsulate` | Decapsulate a hybrid shared secret (_keyId_) |
|
|
225
|
+
| `pqSignKeygen(body)` | `POST /v2/pq/dsa/keygen` | Generate a server-held ML-DSA key pair |
|
|
226
|
+
| `pqSign(body)` | `POST /v2/pq/dsa/sign` | Sign with ML-DSA (_keyId_; level from the key) |
|
|
227
|
+
| `pqVerify(body)` | `POST /v2/pq/dsa/verify` | Verify an ML-DSA signature |
|
|
228
|
+
| `pqHashSignKeygen(body)` | `POST /v2/pq/slh-dsa/keygen` | Generate a server-held SLH-DSA key pair |
|
|
229
|
+
| `pqHashSign(body)` | `POST /v2/pq/slh-dsa/sign` | Sign with SLH-DSA (_keyId_; variant from key) |
|
|
230
|
+
| `pqHashVerify(body)` | `POST /v2/pq/slh-dsa/verify` | Verify an SLH-DSA signature |
|
|
231
|
+
| `getDoraCompliance()` | `GET /v2/compliance/dora` | DORA self-assessment |
|
|
232
|
+
| `getCbom()` | `GET /v2/compliance/cbom` | CycloneDX 1.6 CBOM |
|
|
233
|
+
| `algorithms()` | `GET /v2/algorithms` | List all supported algorithms |
|
|
234
|
+
| `health()` | `GET /health` | Server health check |
|
|
235
|
+
|
|
236
|
+
The stream (`/v2/stream/*`), multi-recipient (`/v2/multi-recipient/encrypt`)
|
|
237
|
+
and v1 OpenPGP routes have no SDK methods yet.
|
|
188
238
|
|
|
189
239
|
<p align="right"><a href="#contents">Back to Top</a></p>
|
|
190
240
|
|
|
@@ -192,28 +242,34 @@ Every method returns `Promise<ApiResponse<T>>` where
|
|
|
192
242
|
|
|
193
243
|
All examples are self-contained TypeScript files in the `examples/`
|
|
194
244
|
directory. Each requires the crypto-server running on
|
|
195
|
-
`http://localhost:3000` (override via `CRYPTO_SERVER_URL`)
|
|
245
|
+
`http://localhost:3000` (override via `CRYPTO_SERVER_URL`) and sends
|
|
246
|
+
`CRYPTO_API_KEY` (or the JWT in `CRYPTO_TOKEN`) when set.
|
|
247
|
+
`pnpm run examples:check` type-checks them against the SDK.
|
|
196
248
|
|
|
197
249
|
```bash
|
|
198
|
-
npx ts-node examples/<name>.ts
|
|
250
|
+
CRYPTO_API_KEY=<key> npx ts-node examples/<name>.ts
|
|
199
251
|
```
|
|
200
252
|
|
|
201
|
-
| Category | Example | Purpose
|
|
202
|
-
| :----------- | :-------------------------------------- |
|
|
203
|
-
| Algorithms | [algorithms.ts](examples/algorithms.ts) | List all supported algorithms
|
|
204
|
-
| Encryption | [encrypt.ts](examples/encrypt.ts) |
|
|
205
|
-
| Hashing | [hash.ts](examples/hash.ts) | Compute SHA-256 and BLAKE2b digests
|
|
206
|
-
| KDF | [kdf.ts](examples/kdf.ts) | Key derivation with HKDF-SHA256
|
|
207
|
-
| Key Gen | [keygen.ts](examples/keygen.ts) | Generate key pairs
|
|
208
|
-
| Key Wrap | [keywrap.ts](examples/keywrap.ts) | AES key wrapping and unwrapping
|
|
209
|
-
| MAC | [mac.ts](examples/mac.ts) | HMAC-SHA256 compute and verify
|
|
210
|
-
| Passwords | [password.ts](examples/password.ts) | Argon2 hashing and password encryption
|
|
211
|
-
| PQ KEM | [pqkem.ts](examples/pqkem.ts) | Hybrid X25519 + ML-KEM key exchange
|
|
212
|
-
| PQ Sign | [pqsign.ts](examples/pqsign.ts) | ML-DSA post-quantum signing
|
|
213
|
-
| PQ Hash Sign | [pqhashsign.ts](examples/pqhashsign.ts) | SLH-DSA post-quantum signing
|
|
214
|
-
| Sealed Box | [sealedbox.ts](examples/sealedbox.ts) | Anonymous public-key encryption
|
|
215
|
-
| Secretbox | [secretbox.ts](examples/secretbox.ts) | Symmetric authenticated encryption
|
|
216
|
-
| Signing | [sign.ts](examples/sign.ts) | Ed25519 signing and verification
|
|
253
|
+
| Category | Example | Purpose |
|
|
254
|
+
| :----------- | :-------------------------------------- | :--------------------------------------------- |
|
|
255
|
+
| Algorithms | [algorithms.ts](examples/algorithms.ts) | List all supported algorithms |
|
|
256
|
+
| Encryption | [encrypt.ts](examples/encrypt.ts) | XChaCha20-Poly1305 encrypt and decrypt |
|
|
257
|
+
| Hashing | [hash.ts](examples/hash.ts) | Compute SHA-256, SHA-512 and BLAKE2b digests |
|
|
258
|
+
| KDF | [kdf.ts](examples/kdf.ts) | Key derivation with HKDF-SHA256 |
|
|
259
|
+
| Key Gen | [keygen.ts](examples/keygen.ts) | Generate server-held key pairs |
|
|
260
|
+
| Key Wrap | [keywrap.ts](examples/keywrap.ts) | AES key wrapping and unwrapping |
|
|
261
|
+
| MAC | [mac.ts](examples/mac.ts) | HMAC-SHA256 compute and verify |
|
|
262
|
+
| Passwords | [password.ts](examples/password.ts) | Argon2 hashing and password encryption |
|
|
263
|
+
| PQ KEM | [pqkem.ts](examples/pqkem.ts) | Hybrid X25519 + ML-KEM key exchange by keyId |
|
|
264
|
+
| PQ Sign | [pqsign.ts](examples/pqsign.ts) | ML-DSA post-quantum signing by keyId |
|
|
265
|
+
| PQ Hash Sign | [pqhashsign.ts](examples/pqhashsign.ts) | SLH-DSA post-quantum signing by keyId |
|
|
266
|
+
| Sealed Box | [sealedbox.ts](examples/sealedbox.ts) | Anonymous public-key encryption, open by keyId |
|
|
267
|
+
| Secretbox | [secretbox.ts](examples/secretbox.ts) | Symmetric authenticated encryption |
|
|
268
|
+
| Signing | [sign.ts](examples/sign.ts) | Ed25519 signing by keyId and verification |
|
|
269
|
+
|
|
270
|
+
`__tests__/contract.test.ts` runs the SDK against the real crypto-server
|
|
271
|
+
in process (its `fetch` forwards to Fastify's `inject`), so a drift
|
|
272
|
+
between a method and its route fails the test suite.
|
|
217
273
|
|
|
218
274
|
<p align="right"><a href="#contents">Back to Top</a></p>
|
|
219
275
|
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ApiError } from "./types";
|
|
2
|
+
export declare class CryptoApiError extends Error {
|
|
3
|
+
readonly status: number;
|
|
4
|
+
readonly body: ApiError;
|
|
5
|
+
constructor(status: number, body: ApiError);
|
|
6
|
+
}
|
|
7
|
+
export declare function readProblem(res: Response): Promise<ApiError>;
|
|
8
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAiBxC,qBAAa,cAAe,SAAQ,KAAK;IAEvC,SAAgB,MAAM,EAAE,MAAM,CAAC;IAE/B,SAAgB,IAAI,EAAE,QAAQ,CAAC;gBAEnB,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ;CAM3C;AAiBD,wBAAsB,WAAW,CAAC,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CASlE"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CryptoApiError = void 0;
|
|
4
|
+
exports.readProblem = readProblem;
|
|
5
|
+
class CryptoApiError extends Error {
|
|
6
|
+
status;
|
|
7
|
+
body;
|
|
8
|
+
constructor(status, body) {
|
|
9
|
+
super(`API Error ${status}: ${body.detail}`);
|
|
10
|
+
this.name = "CryptoApiError";
|
|
11
|
+
this.status = status;
|
|
12
|
+
this.body = body;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.CryptoApiError = CryptoApiError;
|
|
16
|
+
function isProblem(body) {
|
|
17
|
+
return (typeof body === "object" &&
|
|
18
|
+
body !== null &&
|
|
19
|
+
typeof body.detail === "string");
|
|
20
|
+
}
|
|
21
|
+
async function readProblem(res) {
|
|
22
|
+
const body = await res.json().catch(() => undefined);
|
|
23
|
+
if (isProblem(body))
|
|
24
|
+
return body;
|
|
25
|
+
return {
|
|
26
|
+
type: "about:blank",
|
|
27
|
+
title: res.statusText || "HTTP error",
|
|
28
|
+
status: res.status,
|
|
29
|
+
detail: `The server answered ${res.status} without a problem body`,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=errors.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,176 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
export interface ApiResponse<T> {
|
|
8
|
-
data: T;
|
|
9
|
-
}
|
|
10
|
-
export interface ApiError {
|
|
11
|
-
error: string;
|
|
12
|
-
details?: Array<{
|
|
13
|
-
field: string;
|
|
14
|
-
message: string;
|
|
15
|
-
}>;
|
|
16
|
-
}
|
|
17
|
-
export interface HashResult {
|
|
18
|
-
digest: string;
|
|
19
|
-
algorithm: string;
|
|
20
|
-
length: number;
|
|
21
|
-
}
|
|
22
|
-
export interface AeadResult {
|
|
23
|
-
ciphertext: string;
|
|
24
|
-
algorithm: string;
|
|
25
|
-
}
|
|
26
|
-
export interface KdfResult {
|
|
27
|
-
derivedKey: string;
|
|
28
|
-
salt: string;
|
|
29
|
-
algorithm: string;
|
|
30
|
-
keyLength: number;
|
|
31
|
-
}
|
|
32
|
-
export interface Ed25519KeyPair {
|
|
33
|
-
privateKey: string;
|
|
34
|
-
publicKey: string;
|
|
35
|
-
}
|
|
36
|
-
export interface SignResult {
|
|
37
|
-
signature: string;
|
|
38
|
-
algorithm: string;
|
|
39
|
-
}
|
|
40
|
-
export interface VerifyResult {
|
|
41
|
-
valid: boolean;
|
|
42
|
-
algorithm: string;
|
|
43
|
-
}
|
|
44
|
-
export interface HybridKeyPair {
|
|
45
|
-
x25519PrivateKey: string;
|
|
46
|
-
x25519PublicKey: string;
|
|
47
|
-
mlKemPublicKey: string;
|
|
48
|
-
mlKemSecretKey: string;
|
|
49
|
-
algorithm: string;
|
|
50
|
-
}
|
|
51
|
-
export interface HybridEncapsulateResult {
|
|
52
|
-
x25519EphemeralPublic: string;
|
|
53
|
-
mlKemCiphertext: string;
|
|
54
|
-
sharedSecret: string;
|
|
55
|
-
algorithm: string;
|
|
56
|
-
}
|
|
57
|
-
export interface MlDsaKeyPair {
|
|
58
|
-
publicKey: string;
|
|
59
|
-
secretKey: string;
|
|
60
|
-
algorithm: string;
|
|
61
|
-
}
|
|
62
|
-
export interface MlDsaSignResult {
|
|
63
|
-
signature: string;
|
|
64
|
-
algorithm: string;
|
|
65
|
-
}
|
|
66
|
-
export interface MlDsaVerifyResult {
|
|
67
|
-
valid: boolean;
|
|
68
|
-
algorithm: string;
|
|
69
|
-
}
|
|
70
|
-
export interface SlhDsaKeyPair {
|
|
71
|
-
publicKey: string;
|
|
72
|
-
secretKey: string;
|
|
73
|
-
algorithm: string;
|
|
74
|
-
}
|
|
75
|
-
export interface SlhDsaSignResult {
|
|
76
|
-
signature: string;
|
|
77
|
-
algorithm: string;
|
|
78
|
-
}
|
|
79
|
-
export interface SlhDsaVerifyResult {
|
|
80
|
-
valid: boolean;
|
|
81
|
-
algorithm: string;
|
|
82
|
-
}
|
|
83
|
-
export interface SecretboxSealResult {
|
|
84
|
-
sealed: string;
|
|
85
|
-
}
|
|
86
|
-
export interface SealedboxSealResult {
|
|
87
|
-
sealed: string;
|
|
88
|
-
ephemeralPublicKey: string;
|
|
89
|
-
}
|
|
90
|
-
export interface PasswordEncryptResult {
|
|
91
|
-
ciphertext: string;
|
|
92
|
-
}
|
|
93
|
-
export interface KeyWrapResult {
|
|
94
|
-
wrappedKey: string;
|
|
95
|
-
}
|
|
96
|
-
export interface KeyGenerateResult {
|
|
97
|
-
publicKey: string;
|
|
98
|
-
privateKey: string;
|
|
99
|
-
algorithm: string;
|
|
100
|
-
kid: string;
|
|
101
|
-
}
|
|
102
|
-
export interface DoraComplianceScorecard {
|
|
103
|
-
standard: string;
|
|
104
|
-
article: string;
|
|
105
|
-
status: string;
|
|
106
|
-
disclaimer: string;
|
|
107
|
-
quantumResistanceRatio: number;
|
|
108
|
-
activePrimitivesCount: number;
|
|
109
|
-
postQuantumPrimitivesCount: number;
|
|
110
|
-
algorithmDeprecationSchedule: Array<{
|
|
111
|
-
algorithm: string;
|
|
112
|
-
category: string;
|
|
113
|
-
sunsetDate: string;
|
|
114
|
-
recommendedMigration: string;
|
|
115
|
-
}>;
|
|
116
|
-
cryptographicInventory: Array<{
|
|
117
|
-
package: string;
|
|
118
|
-
version: string;
|
|
119
|
-
status: string;
|
|
120
|
-
fipsCompliance: string;
|
|
121
|
-
}>;
|
|
122
|
-
timestamp: string;
|
|
123
|
-
}
|
|
124
|
-
export interface CbomExportPayload {
|
|
125
|
-
bomFormat: string;
|
|
126
|
-
specVersion: string;
|
|
127
|
-
serialNumber: string;
|
|
128
|
-
version: number;
|
|
129
|
-
metadata: Record<string, unknown>;
|
|
130
|
-
components: Array<Record<string, unknown>>;
|
|
131
|
-
}
|
|
132
|
-
export interface AlgorithmNegotiationOptions {
|
|
133
|
-
maxPayloadBytes?: number;
|
|
134
|
-
securityCategoryMin?: 1 | 3 | 5;
|
|
135
|
-
requireHybrid?: boolean;
|
|
136
|
-
clientSupportedAlgorithms?: string[];
|
|
137
|
-
}
|
|
138
|
-
export interface AlgorithmNegotiationResult {
|
|
139
|
-
selectedAlgorithm: string;
|
|
140
|
-
cipherCategory: "lattice-kem" | "hybrid-kem" | "classical-ecdh";
|
|
141
|
-
securityCategory: 1 | 3 | 5;
|
|
142
|
-
isHybrid: boolean;
|
|
143
|
-
publicKeyBytes: number;
|
|
144
|
-
ciphertextBytes: number;
|
|
145
|
-
totalPayloadOverhead: number;
|
|
146
|
-
fitsWithinMtu: boolean;
|
|
147
|
-
fallbackChain: string[];
|
|
148
|
-
compliancePosture: {
|
|
149
|
-
standard: string;
|
|
150
|
-
doraArticle13Compliant: boolean;
|
|
151
|
-
fipsStandard: string;
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
export interface MacResult {
|
|
155
|
-
mac: string;
|
|
156
|
-
algorithm: string;
|
|
157
|
-
}
|
|
158
|
-
export interface PasswordHashResult {
|
|
159
|
-
hash: string;
|
|
160
|
-
salt: string;
|
|
161
|
-
params: {
|
|
162
|
-
t: number;
|
|
163
|
-
m: number;
|
|
164
|
-
p: number;
|
|
165
|
-
};
|
|
166
|
-
algorithm: string;
|
|
167
|
-
phc: string;
|
|
168
|
-
}
|
|
1
|
+
import type { ClientOptions, ApiResponse, HashAlgorithm, HashResult, AeadResult, KdfAlgorithm, KdfResult, SecretboxSealResult, PasswordEncryptResult, KeyWrapAlgorithm, KeyWrapResult, HealthResult, DoraComplianceScorecard, CbomExportPayload, AlgorithmNegotiationOptions, AlgorithmNegotiationResult, HmacAlgorithm, MacResult, MacVerifyResult, Argon2Params, PasswordHashResult } from "./types";
|
|
2
|
+
import type { KeyAlgorithm, KeyIdParams, SignParams, KeyMetadata, KeyGenerateResult, KeyExportResult, SignResult, VerifyResult, MlKemKeyPair, MlKemEncapsulateResult, KemDecapsulateResult, HybridKeyPair, HybridEncapsulateResult, MlDsaLevel, MlDsaKeyPair, MlDsaSignResult, MlDsaVerifyResult, SlhDsaVariant, SlhDsaKeyPair, SlhDsaSignResult, SlhDsaVerifyResult, SealedboxSealResult } from "./key-types";
|
|
3
|
+
export * from "./types";
|
|
4
|
+
export * from "./key-types";
|
|
5
|
+
export { CryptoApiError } from "./errors";
|
|
169
6
|
export declare class CryptoClient {
|
|
170
7
|
private baseUrl;
|
|
171
8
|
private headers;
|
|
172
9
|
private fetchFn;
|
|
173
10
|
constructor(options: ClientOptions);
|
|
11
|
+
private send;
|
|
174
12
|
private request;
|
|
175
13
|
encrypt(params: {
|
|
176
14
|
key: string;
|
|
@@ -183,32 +21,35 @@ export declare class CryptoClient {
|
|
|
183
21
|
plaintext: string;
|
|
184
22
|
}>>;
|
|
185
23
|
hash(params: {
|
|
186
|
-
algorithm:
|
|
24
|
+
algorithm: HashAlgorithm;
|
|
187
25
|
data: string;
|
|
188
26
|
}): Promise<ApiResponse<HashResult>>;
|
|
189
27
|
kdf(params: {
|
|
190
|
-
algorithm:
|
|
28
|
+
algorithm: KdfAlgorithm;
|
|
191
29
|
password: string;
|
|
192
30
|
salt?: string;
|
|
193
31
|
keyLength?: number;
|
|
194
|
-
params?:
|
|
32
|
+
params?: {
|
|
33
|
+
N?: number;
|
|
34
|
+
r?: number;
|
|
35
|
+
p?: number;
|
|
36
|
+
iterations?: number;
|
|
37
|
+
info?: string;
|
|
38
|
+
};
|
|
195
39
|
}): Promise<ApiResponse<KdfResult>>;
|
|
196
40
|
mac(params: {
|
|
197
|
-
algorithm:
|
|
41
|
+
algorithm: HmacAlgorithm;
|
|
198
42
|
key: string;
|
|
199
43
|
data: string;
|
|
200
44
|
}): Promise<ApiResponse<MacResult>>;
|
|
201
45
|
macVerify(params: {
|
|
202
|
-
algorithm:
|
|
46
|
+
algorithm: HmacAlgorithm;
|
|
203
47
|
key: string;
|
|
204
48
|
data: string;
|
|
205
49
|
mac: string;
|
|
206
|
-
}): Promise<ApiResponse<
|
|
207
|
-
valid: boolean;
|
|
208
|
-
}>>;
|
|
50
|
+
}): Promise<ApiResponse<MacVerifyResult>>;
|
|
209
51
|
passwordHash(params: {
|
|
210
52
|
password: string;
|
|
211
|
-
variant?: string;
|
|
212
53
|
timeCost?: number;
|
|
213
54
|
memoryCost?: number;
|
|
214
55
|
parallelism?: number;
|
|
@@ -217,69 +58,56 @@ export declare class CryptoClient {
|
|
|
217
58
|
password: string;
|
|
218
59
|
hash: string;
|
|
219
60
|
salt: string;
|
|
220
|
-
params:
|
|
221
|
-
t: number;
|
|
222
|
-
m: number;
|
|
223
|
-
p: number;
|
|
224
|
-
};
|
|
225
|
-
variant?: string;
|
|
61
|
+
params: Argon2Params;
|
|
226
62
|
}): Promise<ApiResponse<{
|
|
227
63
|
valid: boolean;
|
|
228
64
|
}>>;
|
|
229
65
|
generateKeyPair(params?: {
|
|
230
|
-
algorithm?:
|
|
231
|
-
metadata?:
|
|
66
|
+
algorithm?: KeyAlgorithm;
|
|
67
|
+
metadata?: KeyMetadata;
|
|
232
68
|
}): Promise<ApiResponse<KeyGenerateResult>>;
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
message: string;
|
|
236
|
-
}): Promise<ApiResponse<SignResult>>;
|
|
69
|
+
exportKey(params: KeyIdParams): Promise<ApiResponse<KeyExportResult>>;
|
|
70
|
+
sign(params: SignParams): Promise<ApiResponse<SignResult>>;
|
|
237
71
|
verify(params: {
|
|
238
72
|
publicKey: string;
|
|
239
73
|
message: string;
|
|
240
74
|
signature: string;
|
|
241
75
|
}): Promise<ApiResponse<VerifyResult>>;
|
|
76
|
+
mlKemGenerateKeyPair(): Promise<ApiResponse<MlKemKeyPair>>;
|
|
77
|
+
mlKemEncapsulate(params: {
|
|
78
|
+
publicKey: string;
|
|
79
|
+
}): Promise<ApiResponse<MlKemEncapsulateResult>>;
|
|
80
|
+
mlKemDecapsulate(params: KeyIdParams & {
|
|
81
|
+
ciphertext: string;
|
|
82
|
+
}): Promise<ApiResponse<KemDecapsulateResult>>;
|
|
242
83
|
pqGenerateKeyPair(): Promise<ApiResponse<HybridKeyPair>>;
|
|
243
84
|
pqEncapsulate(params: {
|
|
244
85
|
x25519PublicKey: string;
|
|
245
86
|
mlKemPublicKey: string;
|
|
246
87
|
}): Promise<ApiResponse<HybridEncapsulateResult>>;
|
|
247
|
-
pqDecapsulate(params: {
|
|
248
|
-
x25519PrivateKey: string;
|
|
249
|
-
mlKemSecretKey: string;
|
|
88
|
+
pqDecapsulate(params: KeyIdParams & {
|
|
250
89
|
x25519EphemeralPublic: string;
|
|
251
90
|
mlKemCiphertext: string;
|
|
252
|
-
}): Promise<ApiResponse<
|
|
253
|
-
|
|
254
|
-
algorithm: string;
|
|
255
|
-
}>>;
|
|
256
|
-
pqSign(params: {
|
|
257
|
-
level: 44 | 65 | 87;
|
|
258
|
-
secretKey: string;
|
|
259
|
-
message: string;
|
|
260
|
-
}): Promise<ApiResponse<MlDsaSignResult>>;
|
|
91
|
+
}): Promise<ApiResponse<KemDecapsulateResult>>;
|
|
92
|
+
pqSign(params: SignParams): Promise<ApiResponse<MlDsaSignResult>>;
|
|
261
93
|
pqVerify(params: {
|
|
262
|
-
level:
|
|
94
|
+
level: MlDsaLevel;
|
|
263
95
|
publicKey: string;
|
|
264
96
|
message: string;
|
|
265
97
|
signature: string;
|
|
266
98
|
}): Promise<ApiResponse<MlDsaVerifyResult>>;
|
|
267
99
|
pqSignKeygen(params: {
|
|
268
|
-
level:
|
|
100
|
+
level: MlDsaLevel;
|
|
269
101
|
}): Promise<ApiResponse<MlDsaKeyPair>>;
|
|
270
|
-
pqHashSign(params:
|
|
271
|
-
variant: string;
|
|
272
|
-
secretKey: string;
|
|
273
|
-
message: string;
|
|
274
|
-
}): Promise<ApiResponse<SlhDsaSignResult>>;
|
|
102
|
+
pqHashSign(params: SignParams): Promise<ApiResponse<SlhDsaSignResult>>;
|
|
275
103
|
pqHashVerify(params: {
|
|
276
|
-
variant:
|
|
104
|
+
variant: SlhDsaVariant;
|
|
277
105
|
publicKey: string;
|
|
278
106
|
message: string;
|
|
279
107
|
signature: string;
|
|
280
108
|
}): Promise<ApiResponse<SlhDsaVerifyResult>>;
|
|
281
109
|
pqHashSignKeygen(params: {
|
|
282
|
-
variant:
|
|
110
|
+
variant: SlhDsaVariant;
|
|
283
111
|
}): Promise<ApiResponse<SlhDsaKeyPair>>;
|
|
284
112
|
secretboxSeal(params: {
|
|
285
113
|
key: string;
|
|
@@ -290,19 +118,22 @@ export declare class CryptoClient {
|
|
|
290
118
|
key: string;
|
|
291
119
|
ciphertext: string;
|
|
292
120
|
aad?: string;
|
|
293
|
-
}): Promise<ApiResponse<
|
|
294
|
-
plaintext: string;
|
|
295
|
-
}>>;
|
|
121
|
+
}): Promise<ApiResponse<string>>;
|
|
296
122
|
sealedboxSeal(params: {
|
|
297
123
|
recipientPublicKey: string;
|
|
298
124
|
plaintext: string;
|
|
299
125
|
}): Promise<ApiResponse<SealedboxSealResult>>;
|
|
300
|
-
sealedboxOpen(params: {
|
|
301
|
-
recipientSecretKey: string;
|
|
126
|
+
sealedboxOpen(params: KeyIdParams & {
|
|
302
127
|
sealed: string;
|
|
303
|
-
}): Promise<ApiResponse<
|
|
128
|
+
}): Promise<ApiResponse<string>>;
|
|
129
|
+
sealedboxSealPq(params: {
|
|
130
|
+
x25519PublicKey: string;
|
|
131
|
+
mlKemPublicKey: string;
|
|
304
132
|
plaintext: string;
|
|
305
|
-
}>>;
|
|
133
|
+
}): Promise<ApiResponse<SealedboxSealResult>>;
|
|
134
|
+
sealedboxOpenPq(params: KeyIdParams & {
|
|
135
|
+
sealed: string;
|
|
136
|
+
}): Promise<ApiResponse<string>>;
|
|
306
137
|
passwordEncrypt(params: {
|
|
307
138
|
password: string;
|
|
308
139
|
plaintext: string;
|
|
@@ -310,32 +141,21 @@ export declare class CryptoClient {
|
|
|
310
141
|
passwordDecrypt(params: {
|
|
311
142
|
password: string;
|
|
312
143
|
ciphertext: string;
|
|
313
|
-
}): Promise<ApiResponse<
|
|
314
|
-
plaintext: string;
|
|
315
|
-
}>>;
|
|
144
|
+
}): Promise<ApiResponse<string>>;
|
|
316
145
|
keyWrap(params: {
|
|
317
146
|
kek: string;
|
|
318
147
|
keyToWrap: string;
|
|
319
|
-
algorithm?:
|
|
148
|
+
algorithm?: KeyWrapAlgorithm;
|
|
320
149
|
}): Promise<ApiResponse<KeyWrapResult>>;
|
|
321
150
|
keyUnwrap(params: {
|
|
322
151
|
kek: string;
|
|
323
152
|
wrappedKey: string;
|
|
324
|
-
algorithm?:
|
|
325
|
-
}): Promise<ApiResponse<
|
|
326
|
-
key: string;
|
|
327
|
-
}>>;
|
|
153
|
+
algorithm?: KeyWrapAlgorithm;
|
|
154
|
+
}): Promise<ApiResponse<string>>;
|
|
328
155
|
getDoraCompliance(): Promise<ApiResponse<DoraComplianceScorecard>>;
|
|
329
|
-
getCbom(): Promise<
|
|
156
|
+
getCbom(): Promise<CbomExportPayload>;
|
|
330
157
|
negotiateAlgorithm(options?: AlgorithmNegotiationOptions): AlgorithmNegotiationResult;
|
|
331
158
|
algorithms(): Promise<ApiResponse<Record<string, string[]>>>;
|
|
332
|
-
health(): Promise<
|
|
333
|
-
statusCode: number;
|
|
334
|
-
}>;
|
|
335
|
-
}
|
|
336
|
-
export declare class CryptoApiError extends Error {
|
|
337
|
-
readonly status: number;
|
|
338
|
-
readonly body: ApiError;
|
|
339
|
-
constructor(status: number, body: ApiError);
|
|
159
|
+
health(): Promise<HealthResult>;
|
|
340
160
|
}
|
|
341
161
|
//# sourceMappingURL=index.d.ts.map
|