@qpher/sdk 0.1.0
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/LICENSE +21 -0
- package/README.md +266 -0
- package/dist/client.d.ts +32 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +55 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +35 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +106 -0
- package/dist/errors.js.map +1 -0
- package/dist/esm/client.d.ts +32 -0
- package/dist/esm/client.d.ts.map +1 -0
- package/dist/esm/client.js +51 -0
- package/dist/esm/client.js.map +1 -0
- package/dist/esm/errors.d.ts +35 -0
- package/dist/esm/errors.d.ts.map +1 -0
- package/dist/esm/errors.js +93 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/http-client.d.ts +21 -0
- package/dist/esm/http-client.d.ts.map +1 -0
- package/dist/esm/http-client.js +104 -0
- package/dist/esm/http-client.js.map +1 -0
- package/dist/esm/index.d.ts +10 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +12 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/kem.d.ts +24 -0
- package/dist/esm/kem.d.ts.map +1 -0
- package/dist/esm/kem.js +52 -0
- package/dist/esm/kem.js.map +1 -0
- package/dist/esm/keys.d.ts +52 -0
- package/dist/esm/keys.d.ts.map +1 -0
- package/dist/esm/keys.js +110 -0
- package/dist/esm/keys.js.map +1 -0
- package/dist/esm/signatures.d.ts +24 -0
- package/dist/esm/signatures.d.ts.map +1 -0
- package/dist/esm/signatures.js +49 -0
- package/dist/esm/signatures.js.map +1 -0
- package/dist/esm/types.d.ts +122 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +5 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/http-client.d.ts +21 -0
- package/dist/http-client.d.ts.map +1 -0
- package/dist/http-client.js +108 -0
- package/dist/http-client.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/kem.d.ts +24 -0
- package/dist/kem.d.ts.map +1 -0
- package/dist/kem.js +56 -0
- package/dist/kem.js.map +1 -0
- package/dist/keys.d.ts +52 -0
- package/dist/keys.d.ts.map +1 -0
- package/dist/keys.js +114 -0
- package/dist/keys.js.map +1 -0
- package/dist/signatures.d.ts +24 -0
- package/dist/signatures.d.ts.map +1 -0
- package/dist/signatures.js +53 -0
- package/dist/signatures.js.map +1 -0
- package/dist/types.d.ts +122 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/package.json +55 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Qpher SDK error classes.
|
|
3
|
+
*/
|
|
4
|
+
export class QpherError extends Error {
|
|
5
|
+
errorCode;
|
|
6
|
+
statusCode;
|
|
7
|
+
requestId;
|
|
8
|
+
constructor(message, errorCode, statusCode, requestId) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = 'QpherError';
|
|
11
|
+
this.errorCode = errorCode;
|
|
12
|
+
this.statusCode = statusCode;
|
|
13
|
+
this.requestId = requestId;
|
|
14
|
+
// Maintain proper stack trace for where error was thrown (only available on V8)
|
|
15
|
+
if (Error.captureStackTrace) {
|
|
16
|
+
Error.captureStackTrace(this, QpherError);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export class AuthenticationError extends QpherError {
|
|
21
|
+
constructor(message, errorCode, requestId) {
|
|
22
|
+
super(message, errorCode, 401, requestId);
|
|
23
|
+
this.name = 'AuthenticationError';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export class ValidationError extends QpherError {
|
|
27
|
+
constructor(message, errorCode, requestId) {
|
|
28
|
+
super(message, errorCode, 400, requestId);
|
|
29
|
+
this.name = 'ValidationError';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export class NotFoundError extends QpherError {
|
|
33
|
+
constructor(message, errorCode, requestId) {
|
|
34
|
+
super(message, errorCode, 404, requestId);
|
|
35
|
+
this.name = 'NotFoundError';
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export class ForbiddenError extends QpherError {
|
|
39
|
+
constructor(message, errorCode, requestId) {
|
|
40
|
+
super(message, errorCode, 403, requestId);
|
|
41
|
+
this.name = 'ForbiddenError';
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export class RateLimitError extends QpherError {
|
|
45
|
+
constructor(message, errorCode, requestId) {
|
|
46
|
+
super(message, errorCode, 429, requestId);
|
|
47
|
+
this.name = 'RateLimitError';
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export class ServerError extends QpherError {
|
|
51
|
+
constructor(message, errorCode, statusCode, requestId) {
|
|
52
|
+
super(message, errorCode, statusCode, requestId);
|
|
53
|
+
this.name = 'ServerError';
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export class TimeoutError extends QpherError {
|
|
57
|
+
constructor(message, requestId) {
|
|
58
|
+
super(message, 'ERR_TIMEOUT_001', 504, requestId);
|
|
59
|
+
this.name = 'TimeoutError';
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
export class ConnectionError extends QpherError {
|
|
63
|
+
constructor(message, requestId) {
|
|
64
|
+
super(message, 'ERR_SERVICE_001', 503, requestId);
|
|
65
|
+
this.name = 'ConnectionError';
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const STATUS_TO_ERROR = {
|
|
69
|
+
400: ValidationError,
|
|
70
|
+
401: AuthenticationError,
|
|
71
|
+
403: ForbiddenError,
|
|
72
|
+
404: NotFoundError,
|
|
73
|
+
429: RateLimitError,
|
|
74
|
+
};
|
|
75
|
+
export function parseErrorResponse(statusCode, body, fallbackMessage) {
|
|
76
|
+
let errorCode = `ERR_UNKNOWN_${statusCode}`;
|
|
77
|
+
let message = fallbackMessage;
|
|
78
|
+
let requestId;
|
|
79
|
+
if (body && typeof body === 'object') {
|
|
80
|
+
const errorBody = body;
|
|
81
|
+
if (errorBody.error) {
|
|
82
|
+
errorCode = errorBody.error.error_code ?? errorCode;
|
|
83
|
+
message = errorBody.error.message ?? message;
|
|
84
|
+
}
|
|
85
|
+
requestId = errorBody.request_id;
|
|
86
|
+
}
|
|
87
|
+
const ErrorClass = STATUS_TO_ERROR[statusCode];
|
|
88
|
+
if (ErrorClass) {
|
|
89
|
+
return new ErrorClass(message, errorCode, requestId);
|
|
90
|
+
}
|
|
91
|
+
return new ServerError(message, errorCode, statusCode, requestId);
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,OAAO,UAAW,SAAQ,KAAK;IACnB,SAAS,CAAS;IAClB,UAAU,CAAS;IACnB,SAAS,CAAU;IAEnC,YACE,OAAe,EACf,SAAiB,EACjB,UAAkB,EAClB,SAAkB;QAElB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;QACzB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAE3B,gFAAgF;QAChF,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;YAC5B,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QAC5C,CAAC;IACH,CAAC;CACF;AAED,MAAM,OAAO,mBAAoB,SAAQ,UAAU;IACjD,YAAY,OAAe,EAAE,SAAiB,EAAE,SAAkB;QAChE,KAAK,CAAC,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,CAAC,CAAC;QAC1C,IAAI,CAAC,IAAI,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;AACpE,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal HTTP client with authentication, retries, and error handling.
|
|
3
|
+
*/
|
|
4
|
+
export interface HttpClientOptions {
|
|
5
|
+
apiKey: string;
|
|
6
|
+
baseUrl: string;
|
|
7
|
+
timeout: number;
|
|
8
|
+
maxRetries: number;
|
|
9
|
+
}
|
|
10
|
+
export declare class HttpClient {
|
|
11
|
+
private readonly apiKey;
|
|
12
|
+
private readonly baseUrl;
|
|
13
|
+
private readonly timeout;
|
|
14
|
+
private readonly maxRetries;
|
|
15
|
+
constructor(options: HttpClientOptions);
|
|
16
|
+
request<T>(method: string, path: string, body?: Record<string, unknown>, params?: Record<string, string>): Promise<T>;
|
|
17
|
+
get<T>(path: string, params?: Record<string, string>): Promise<T>;
|
|
18
|
+
post<T>(path: string, body?: Record<string, unknown>): Promise<T>;
|
|
19
|
+
private backoff;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=http-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-client.d.ts","sourceRoot":"","sources":["../../src/http-client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAYH,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;gBAExB,OAAO,EAAE,iBAAiB;IAOhC,OAAO,CAAC,CAAC,EACb,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC9B,OAAO,CAAC,CAAC,CAAC;IAiGP,GAAG,CAAC,CAAC,EACT,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC9B,OAAO,CAAC,CAAC,CAAC;IAIP,IAAI,CAAC,CAAC,EACV,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,OAAO,CAAC,CAAC,CAAC;YAIC,OAAO;CAItB"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal HTTP client with authentication, retries, and error handling.
|
|
3
|
+
*/
|
|
4
|
+
import { QpherError, TimeoutError, ConnectionError, parseErrorResponse, } from './errors';
|
|
5
|
+
const RETRYABLE_STATUS_CODES = new Set([429, 502, 503, 504]);
|
|
6
|
+
const SDK_VERSION = '0.1.0';
|
|
7
|
+
export class HttpClient {
|
|
8
|
+
apiKey;
|
|
9
|
+
baseUrl;
|
|
10
|
+
timeout;
|
|
11
|
+
maxRetries;
|
|
12
|
+
constructor(options) {
|
|
13
|
+
this.apiKey = options.apiKey;
|
|
14
|
+
this.baseUrl = options.baseUrl;
|
|
15
|
+
this.timeout = options.timeout;
|
|
16
|
+
this.maxRetries = options.maxRetries;
|
|
17
|
+
}
|
|
18
|
+
async request(method, path, body, params) {
|
|
19
|
+
let url = `${this.baseUrl}${path}`;
|
|
20
|
+
if (params && Object.keys(params).length > 0) {
|
|
21
|
+
const searchParams = new URLSearchParams(params);
|
|
22
|
+
url = `${url}?${searchParams.toString()}`;
|
|
23
|
+
}
|
|
24
|
+
let lastError;
|
|
25
|
+
for (let attempt = 0; attempt <= this.maxRetries; attempt++) {
|
|
26
|
+
try {
|
|
27
|
+
const controller = new AbortController();
|
|
28
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
29
|
+
const response = await fetch(url, {
|
|
30
|
+
method,
|
|
31
|
+
headers: {
|
|
32
|
+
'x-api-key': this.apiKey,
|
|
33
|
+
'Content-Type': 'application/json',
|
|
34
|
+
Accept: 'application/json',
|
|
35
|
+
'User-Agent': `qpher-node/${SDK_VERSION}`,
|
|
36
|
+
},
|
|
37
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
38
|
+
signal: controller.signal,
|
|
39
|
+
});
|
|
40
|
+
clearTimeout(timeoutId);
|
|
41
|
+
if (response.status >= 400) {
|
|
42
|
+
let errorBody;
|
|
43
|
+
try {
|
|
44
|
+
errorBody = await response.json();
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
errorBody = { error: { message: await response.text() } };
|
|
48
|
+
}
|
|
49
|
+
const error = parseErrorResponse(response.status, errorBody, `HTTP ${response.status}`);
|
|
50
|
+
if (RETRYABLE_STATUS_CODES.has(response.status) &&
|
|
51
|
+
attempt < this.maxRetries) {
|
|
52
|
+
lastError = error;
|
|
53
|
+
await this.backoff(attempt);
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
return (await response.json());
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
if (error instanceof QpherError) {
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
if (error instanceof Error) {
|
|
65
|
+
if (error.name === 'AbortError') {
|
|
66
|
+
if (attempt < this.maxRetries) {
|
|
67
|
+
lastError = error;
|
|
68
|
+
await this.backoff(attempt);
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
throw new TimeoutError('Request timed out');
|
|
72
|
+
}
|
|
73
|
+
// Connection errors
|
|
74
|
+
if (error.message.includes('fetch failed') ||
|
|
75
|
+
error.message.includes('ECONNREFUSED') ||
|
|
76
|
+
error.message.includes('ENOTFOUND')) {
|
|
77
|
+
if (attempt < this.maxRetries) {
|
|
78
|
+
lastError = error;
|
|
79
|
+
await this.backoff(attempt);
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
throw new ConnectionError('Connection failed');
|
|
83
|
+
}
|
|
84
|
+
lastError = error;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (lastError instanceof QpherError) {
|
|
89
|
+
throw lastError;
|
|
90
|
+
}
|
|
91
|
+
throw new ConnectionError('Request failed after retries');
|
|
92
|
+
}
|
|
93
|
+
async get(path, params) {
|
|
94
|
+
return this.request('GET', path, undefined, params);
|
|
95
|
+
}
|
|
96
|
+
async post(path, body) {
|
|
97
|
+
return this.request('POST', path, body);
|
|
98
|
+
}
|
|
99
|
+
async backoff(attempt) {
|
|
100
|
+
const delay = Math.min(500 * Math.pow(2, attempt), 10000);
|
|
101
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=http-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-client.js","sourceRoot":"","sources":["../../src/http-client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,UAAU,EACV,YAAY,EACZ,eAAe,EACf,kBAAkB,GACnB,MAAM,UAAU,CAAC;AAElB,MAAM,sBAAsB,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AAC7D,MAAM,WAAW,GAAG,OAAO,CAAC;AAS5B,MAAM,OAAO,UAAU;IACJ,MAAM,CAAS;IACf,OAAO,CAAS;IAChB,OAAO,CAAS;IAChB,UAAU,CAAS;IAEpC,YAAY,OAA0B;QACpC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAC/B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAC/B,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Qpher Post-Quantum Cryptography API.
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
export { Qpher } from './client';
|
|
7
|
+
export { QpherError, AuthenticationError, ValidationError, NotFoundError, ForbiddenError, RateLimitError, ServerError, TimeoutError, ConnectionError, } from './errors';
|
|
8
|
+
export { QpherOptions, EncryptInput, EncryptResult, DecryptInput, DecryptResult, SignInput, SignResult, VerifyInput, VerifyResult, KeyInfo, KeyListResult, GenerateInput, GenerateResult, RotateInput, RotateResult, GetActiveInput, GetKeyInput, ListKeysInput, RetireInput, RetireResult, } from './types';
|
|
9
|
+
export declare const version = "0.1.0";
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAGjC,OAAO,EACL,UAAU,EACV,mBAAmB,EACnB,eAAe,EACf,aAAa,EACb,cAAc,EACd,cAAc,EACd,WAAW,EACX,YAAY,EACZ,eAAe,GAChB,MAAM,UAAU,CAAC;AAGlB,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,aAAa,EACb,SAAS,EACT,UAAU,EACV,WAAW,EACX,YAAY,EACZ,OAAO,EACP,aAAa,EACb,aAAa,EACb,cAAc,EACd,WAAW,EACX,YAAY,EACZ,cAAc,EACd,WAAW,EACX,aAAa,EACb,WAAW,EACX,YAAY,GACb,MAAM,SAAS,CAAC;AAGjB,eAAO,MAAM,OAAO,UAAU,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Qpher Node.js SDK - Official client for the Qpher Post-Quantum Cryptography API.
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
// Main client
|
|
7
|
+
export { Qpher } from './client';
|
|
8
|
+
// Errors
|
|
9
|
+
export { QpherError, AuthenticationError, ValidationError, NotFoundError, ForbiddenError, RateLimitError, ServerError, TimeoutError, ConnectionError, } from './errors';
|
|
10
|
+
// SDK version
|
|
11
|
+
export const version = '0.1.0';
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc;AACd,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEjC,SAAS;AACT,OAAO,EACL,UAAU,EACV,mBAAmB,EACnB,eAAe,EACf,aAAa,EACb,cAAc,EACd,cAAc,EACd,WAAW,EACX,YAAY,EACZ,eAAe,GAChB,MAAM,UAAU,CAAC;AA0BlB,cAAc;AACd,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kyber768 KEM encrypt/decrypt operations.
|
|
3
|
+
*/
|
|
4
|
+
import { HttpClient } from './http-client';
|
|
5
|
+
import { EncryptInput, EncryptResult, DecryptInput, DecryptResult } from './types';
|
|
6
|
+
export declare class KEMModule {
|
|
7
|
+
private readonly http;
|
|
8
|
+
constructor(http: HttpClient);
|
|
9
|
+
/**
|
|
10
|
+
* Encrypt data using Kyber768 KEM.
|
|
11
|
+
*
|
|
12
|
+
* @param input - Encryption parameters
|
|
13
|
+
* @returns Encrypted result with ciphertext and metadata
|
|
14
|
+
*/
|
|
15
|
+
encrypt(input: EncryptInput): Promise<EncryptResult>;
|
|
16
|
+
/**
|
|
17
|
+
* Decrypt data using Kyber768 KEM.
|
|
18
|
+
*
|
|
19
|
+
* @param input - Decryption parameters
|
|
20
|
+
* @returns Decrypted result with plaintext and metadata
|
|
21
|
+
*/
|
|
22
|
+
decrypt(input: DecryptInput): Promise<DecryptResult>;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=kem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kem.d.ts","sourceRoot":"","sources":["../../src/kem.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EACL,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,aAAa,EACd,MAAM,SAAS,CAAC;AAsBjB,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAa;gBAEtB,IAAI,EAAE,UAAU;IAI5B;;;;;OAKG;IACG,OAAO,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC;IAwB1D;;;;;OAKG;IACG,OAAO,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC;CAkB3D"}
|
package/dist/esm/kem.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kyber768 KEM encrypt/decrypt operations.
|
|
3
|
+
*/
|
|
4
|
+
export class KEMModule {
|
|
5
|
+
http;
|
|
6
|
+
constructor(http) {
|
|
7
|
+
this.http = http;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Encrypt data using Kyber768 KEM.
|
|
11
|
+
*
|
|
12
|
+
* @param input - Encryption parameters
|
|
13
|
+
* @returns Encrypted result with ciphertext and metadata
|
|
14
|
+
*/
|
|
15
|
+
async encrypt(input) {
|
|
16
|
+
const body = {
|
|
17
|
+
plaintext: input.plaintext.toString('base64'),
|
|
18
|
+
key_version: input.keyVersion,
|
|
19
|
+
mode: input.mode ?? 'standard',
|
|
20
|
+
};
|
|
21
|
+
if (input.salt) {
|
|
22
|
+
body.salt = input.salt.toString('base64');
|
|
23
|
+
}
|
|
24
|
+
const response = await this.http.post('/api/v1/kem/encrypt', body);
|
|
25
|
+
return {
|
|
26
|
+
ciphertext: Buffer.from(response.data.ciphertext, 'base64'),
|
|
27
|
+
keyVersion: response.data.key_version,
|
|
28
|
+
algorithm: response.data.algorithm,
|
|
29
|
+
requestId: response.request_id,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Decrypt data using Kyber768 KEM.
|
|
34
|
+
*
|
|
35
|
+
* @param input - Decryption parameters
|
|
36
|
+
* @returns Decrypted result with plaintext and metadata
|
|
37
|
+
*/
|
|
38
|
+
async decrypt(input) {
|
|
39
|
+
const body = {
|
|
40
|
+
ciphertext: input.ciphertext.toString('base64'),
|
|
41
|
+
key_version: input.keyVersion,
|
|
42
|
+
};
|
|
43
|
+
const response = await this.http.post('/api/v1/kem/decrypt', body);
|
|
44
|
+
return {
|
|
45
|
+
plaintext: Buffer.from(response.data.plaintext, 'base64'),
|
|
46
|
+
keyVersion: response.data.key_version,
|
|
47
|
+
algorithm: response.data.algorithm,
|
|
48
|
+
requestId: response.request_id,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=kem.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kem.js","sourceRoot":"","sources":["../../src/kem.ts"],"names":[],"mappings":"AAAA;;GAEG;AA8BH,MAAM,OAAO,SAAS;IACH,IAAI,CAAa;IAElC,YAAY,IAAgB;QAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,OAAO,CAAC,KAAmB;QAC/B,MAAM,IAAI,GAA4B;YACpC,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC;YAC7C,WAAW,EAAE,KAAK,CAAC,UAAU;YAC7B,IAAI,EAAE,KAAK,CAAC,IAAI,IAAI,UAAU;SAC/B,CAAC;QAEF,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;YACf,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAC5C,CAAC;QAED,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CACnC,qBAAqB,EACrB,IAAI,CACL,CAAC;QAEF,OAAO;YACL,UAAU,EAAE,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC;YAC3D,UAAU,EAAE,QAAQ,CAAC,IAAI,CAAC,WAAW;YACrC,SAAS,EAAE,QAAQ,CAAC,IAAI,CAAC,SAAS;YAClC,SAAS,EAAE,QAAQ,CAAC,UAAU;SAC/B,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,OAAO,CAAC,KAAmB;QAC/B,MAAM,IAAI,GAAG;YACX,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC;YAC/C,WAAW,EAAE,KAAK,CAAC,UAAU;SAC9B,CAAC;QAEF,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CACnC,qBAAqB,EACrB,IAAI,CACL,CAAC;QAEF,OAAO;YACL,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC;YACzD,UAAU,EAAE,QAAQ,CAAC,IAAI,CAAC,WAAW;YACrC,SAAS,EAAE,QAAQ,CAAC,IAAI,CAAC,SAAS;YAClC,SAAS,EAAE,QAAQ,CAAC,UAAU;SAC/B,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PQC key lifecycle management.
|
|
3
|
+
*/
|
|
4
|
+
import { HttpClient } from './http-client';
|
|
5
|
+
import { KeyInfo, KeyListResult, GenerateInput, GenerateResult, RotateInput, RotateResult, GetActiveInput, GetKeyInput, ListKeysInput, RetireInput, RetireResult } from './types';
|
|
6
|
+
export declare class KeysModule {
|
|
7
|
+
private readonly http;
|
|
8
|
+
constructor(http: HttpClient);
|
|
9
|
+
/**
|
|
10
|
+
* Generate a new PQC key pair.
|
|
11
|
+
*
|
|
12
|
+
* @param input - Generation parameters
|
|
13
|
+
* @returns Generated key information
|
|
14
|
+
*/
|
|
15
|
+
generate(input: GenerateInput): Promise<GenerateResult>;
|
|
16
|
+
/**
|
|
17
|
+
* Rotate to a new key version. The old active key becomes retired.
|
|
18
|
+
*
|
|
19
|
+
* @param input - Rotation parameters
|
|
20
|
+
* @returns New key information with old key version
|
|
21
|
+
*/
|
|
22
|
+
rotate(input: RotateInput): Promise<RotateResult>;
|
|
23
|
+
/**
|
|
24
|
+
* Get the currently active key for an algorithm.
|
|
25
|
+
*
|
|
26
|
+
* @param input - Query parameters
|
|
27
|
+
* @returns Active key information
|
|
28
|
+
*/
|
|
29
|
+
getActive(input: GetActiveInput): Promise<KeyInfo>;
|
|
30
|
+
/**
|
|
31
|
+
* Get a specific key version.
|
|
32
|
+
*
|
|
33
|
+
* @param input - Query parameters
|
|
34
|
+
* @returns Key information for the specified version
|
|
35
|
+
*/
|
|
36
|
+
get(input: GetKeyInput): Promise<KeyInfo>;
|
|
37
|
+
/**
|
|
38
|
+
* List all PQC keys, optionally filtered.
|
|
39
|
+
*
|
|
40
|
+
* @param input - Filter parameters (optional)
|
|
41
|
+
* @returns List of keys with total count
|
|
42
|
+
*/
|
|
43
|
+
list(input?: ListKeysInput): Promise<KeyListResult>;
|
|
44
|
+
/**
|
|
45
|
+
* Retire a key. Retired keys can decrypt/verify but not encrypt/sign.
|
|
46
|
+
*
|
|
47
|
+
* @param input - Retirement parameters
|
|
48
|
+
* @returns Updated key information
|
|
49
|
+
*/
|
|
50
|
+
retire(input: RetireInput): Promise<RetireResult>;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=keys.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../../src/keys.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EACL,OAAO,EACP,aAAa,EACb,aAAa,EACb,cAAc,EACd,WAAW,EACX,YAAY,EACZ,cAAc,EACd,WAAW,EACX,aAAa,EACb,WAAW,EACX,YAAY,EACb,MAAM,SAAS,CAAC;AAkDjB,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAa;gBAEtB,IAAI,EAAE,UAAU;IAI5B;;;;;OAKG;IACG,QAAQ,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC;IAgB7D;;;;;OAKG;IACG,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;IAevD;;;;;OAKG;IACG,SAAS,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC;IASxD;;;;;OAKG;IACG,GAAG,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;IAS/C;;;;;OAKG;IACG,IAAI,CAAC,KAAK,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;IAqBzD;;;;;OAKG;IACG,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;CAexD"}
|
package/dist/esm/keys.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PQC key lifecycle management.
|
|
3
|
+
*/
|
|
4
|
+
function parseKeyInfo(data) {
|
|
5
|
+
return {
|
|
6
|
+
keyVersion: data.key_version,
|
|
7
|
+
algorithm: data.algorithm,
|
|
8
|
+
status: data.status,
|
|
9
|
+
publicKey: Buffer.from(data.public_key, 'base64'),
|
|
10
|
+
createdAt: data.created_at,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export class KeysModule {
|
|
14
|
+
http;
|
|
15
|
+
constructor(http) {
|
|
16
|
+
this.http = http;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Generate a new PQC key pair.
|
|
20
|
+
*
|
|
21
|
+
* @param input - Generation parameters
|
|
22
|
+
* @returns Generated key information
|
|
23
|
+
*/
|
|
24
|
+
async generate(input) {
|
|
25
|
+
const response = await this.http.post('/api/v1/kms/keys/generate', { algorithm: input.algorithm });
|
|
26
|
+
return {
|
|
27
|
+
keyVersion: response.data.key_version,
|
|
28
|
+
algorithm: response.data.algorithm,
|
|
29
|
+
status: response.data.status,
|
|
30
|
+
publicKey: Buffer.from(response.data.public_key, 'base64'),
|
|
31
|
+
createdAt: response.data.created_at,
|
|
32
|
+
requestId: response.request_id,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Rotate to a new key version. The old active key becomes retired.
|
|
37
|
+
*
|
|
38
|
+
* @param input - Rotation parameters
|
|
39
|
+
* @returns New key information with old key version
|
|
40
|
+
*/
|
|
41
|
+
async rotate(input) {
|
|
42
|
+
const response = await this.http.post('/api/v1/kms/keys/rotate', { algorithm: input.algorithm });
|
|
43
|
+
return {
|
|
44
|
+
keyVersion: response.data.key_version,
|
|
45
|
+
algorithm: response.data.algorithm,
|
|
46
|
+
publicKey: Buffer.from(response.data.public_key, 'base64'),
|
|
47
|
+
oldKeyVersion: response.data.old_key_version,
|
|
48
|
+
requestId: response.request_id,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Get the currently active key for an algorithm.
|
|
53
|
+
*
|
|
54
|
+
* @param input - Query parameters
|
|
55
|
+
* @returns Active key information
|
|
56
|
+
*/
|
|
57
|
+
async getActive(input) {
|
|
58
|
+
const response = await this.http.get('/api/v1/kms/keys/active', { algorithm: input.algorithm });
|
|
59
|
+
return parseKeyInfo(response.data);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Get a specific key version.
|
|
63
|
+
*
|
|
64
|
+
* @param input - Query parameters
|
|
65
|
+
* @returns Key information for the specified version
|
|
66
|
+
*/
|
|
67
|
+
async get(input) {
|
|
68
|
+
const response = await this.http.get(`/api/v1/kms/keys/${input.keyVersion}`, { algorithm: input.algorithm });
|
|
69
|
+
return parseKeyInfo(response.data);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* List all PQC keys, optionally filtered.
|
|
73
|
+
*
|
|
74
|
+
* @param input - Filter parameters (optional)
|
|
75
|
+
* @returns List of keys with total count
|
|
76
|
+
*/
|
|
77
|
+
async list(input) {
|
|
78
|
+
const params = {};
|
|
79
|
+
if (input?.algorithm) {
|
|
80
|
+
params.algorithm = input.algorithm;
|
|
81
|
+
}
|
|
82
|
+
if (input?.status) {
|
|
83
|
+
params.status = input.status;
|
|
84
|
+
}
|
|
85
|
+
const response = await this.http.get('/api/v1/kms/keys', Object.keys(params).length > 0 ? params : undefined);
|
|
86
|
+
return {
|
|
87
|
+
keys: response.data.keys.map(parseKeyInfo),
|
|
88
|
+
total: response.data.total,
|
|
89
|
+
requestId: response.request_id,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Retire a key. Retired keys can decrypt/verify but not encrypt/sign.
|
|
94
|
+
*
|
|
95
|
+
* @param input - Retirement parameters
|
|
96
|
+
* @returns Updated key information
|
|
97
|
+
*/
|
|
98
|
+
async retire(input) {
|
|
99
|
+
const response = await this.http.post('/api/v1/kms/keys/retire', { algorithm: input.algorithm, key_version: input.keyVersion });
|
|
100
|
+
return {
|
|
101
|
+
keyVersion: response.data.key_version,
|
|
102
|
+
algorithm: response.data.algorithm,
|
|
103
|
+
status: response.data.status,
|
|
104
|
+
publicKey: Buffer.from(response.data.public_key, 'base64'),
|
|
105
|
+
createdAt: response.data.created_at,
|
|
106
|
+
requestId: response.request_id,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=keys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keys.js","source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AAI,CAAC,MAAM,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CACpD,CAAC;QAEF,OAAO;YACL,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC;YAC1C,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,KAAK;YAC1B,SAAS,EAAE,QAAQ,CAAC,UAAU;SAC/B,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,MAAM,CAAC,KAAkB;QAC7B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CACnC,yBAAyB,EACzB,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,WAAW,EAAE,KAAK,CAAC,UAAU,EAAE,CAC9D,CAAC;QAEF,OAAO;YACL,UAAU,EAAE,QAAQ,CAAC,IAAI,CAAC,WAAW;YACrC,SAAS,EAAE,QAAQ,CAAC,IAAI,CAAC,SAAS;YAClC,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,MAAM;YAC5B,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC;YAC1D,SAAS,EAAE,QAAQ,CAAC,IAAI,CAAC,UAAU;YACnC,SAAS,EAAE,QAAQ,CAAC,UAAU;SAC/B,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dilithium3 digital signature operations.
|
|
3
|
+
*/
|
|
4
|
+
import { HttpClient } from './http-client';
|
|
5
|
+
import { SignInput, SignResult, VerifyInput, VerifyResult } from './types';
|
|
6
|
+
export declare class SignaturesModule {
|
|
7
|
+
private readonly http;
|
|
8
|
+
constructor(http: HttpClient);
|
|
9
|
+
/**
|
|
10
|
+
* Sign a message using Dilithium3.
|
|
11
|
+
*
|
|
12
|
+
* @param input - Signing parameters
|
|
13
|
+
* @returns Signed result with signature bytes (3,293 bytes raw)
|
|
14
|
+
*/
|
|
15
|
+
sign(input: SignInput): Promise<SignResult>;
|
|
16
|
+
/**
|
|
17
|
+
* Verify a Dilithium3 signature.
|
|
18
|
+
*
|
|
19
|
+
* @param input - Verification parameters
|
|
20
|
+
* @returns Verification result with valid=true/false
|
|
21
|
+
*/
|
|
22
|
+
verify(input: VerifyInput): Promise<VerifyResult>;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=signatures.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signatures.d.ts","sourceRoot":"","sources":["../../src/signatures.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAsB3E,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAa;gBAEtB,IAAI,EAAE,UAAU;IAI5B;;;;;OAKG;IACG,IAAI,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC;IAmBjD;;;;;OAKG;IACG,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;CAmBxD"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dilithium3 digital signature operations.
|
|
3
|
+
*/
|
|
4
|
+
export class SignaturesModule {
|
|
5
|
+
http;
|
|
6
|
+
constructor(http) {
|
|
7
|
+
this.http = http;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Sign a message using Dilithium3.
|
|
11
|
+
*
|
|
12
|
+
* @param input - Signing parameters
|
|
13
|
+
* @returns Signed result with signature bytes (3,293 bytes raw)
|
|
14
|
+
*/
|
|
15
|
+
async sign(input) {
|
|
16
|
+
const body = {
|
|
17
|
+
message: input.message.toString('base64'),
|
|
18
|
+
key_version: input.keyVersion,
|
|
19
|
+
};
|
|
20
|
+
const response = await this.http.post('/api/v1/signature/sign', body);
|
|
21
|
+
return {
|
|
22
|
+
signature: Buffer.from(response.data.signature, 'base64'),
|
|
23
|
+
keyVersion: response.data.key_version,
|
|
24
|
+
algorithm: response.data.algorithm,
|
|
25
|
+
requestId: response.request_id,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Verify a Dilithium3 signature.
|
|
30
|
+
*
|
|
31
|
+
* @param input - Verification parameters
|
|
32
|
+
* @returns Verification result with valid=true/false
|
|
33
|
+
*/
|
|
34
|
+
async verify(input) {
|
|
35
|
+
const body = {
|
|
36
|
+
message: input.message.toString('base64'),
|
|
37
|
+
signature: input.signature.toString('base64'),
|
|
38
|
+
key_version: input.keyVersion,
|
|
39
|
+
};
|
|
40
|
+
const response = await this.http.post('/api/v1/signature/verify', body);
|
|
41
|
+
return {
|
|
42
|
+
valid: response.data.valid,
|
|
43
|
+
keyVersion: response.data.key_version,
|
|
44
|
+
algorithm: response.data.algorithm,
|
|
45
|
+
requestId: response.request_id,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=signatures.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signatures.js","sourceRoot":"","sources":["../../src/signatures.ts"],"names":[],"mappings":"AAAA;;GAEG;AAyBH,MAAM,OAAO,gBAAgB;IACV,IAAI,CAAa;IAElC,YAAY,IAAgB;QAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,IAAI,CAAC,KAAgB;QACzB,MAAM,IAAI,GAAG;YACX,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC;YACzC,WAAW,EAAE,KAAK,CAAC,UAAU;SAC9B,CAAC;QAE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