@ddunigma/node 3.0.0 → 3.0.2

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/dist/index.d.cts CHANGED
@@ -1,784 +1,103 @@
1
- import { Transform, TransformCallback, TransformOptions } from 'stream';
1
+ import { D as Ddu64Core, a as DduConstructorOptions, b as DduOptions, P as PlatformAdapter, K as KeyDerivationOptions } from './core-BccIjoLZ.cjs';
2
+ export { C as CharSetConfig, c as CharSetInfo, d as CharsetBuilder, e as DduEncodeStats, f as DduProgressInfo, g as DduSetSymbol, E as EncoderConfig, h as KeyDerivationAlgorithm, O as ObfuscationLayer, T as TestVector, W as WasmCodec, i as WorkerPool, j as getWasmCodec, k as getWasmCodecSync, p as preloadWasm } from './core-BccIjoLZ.cjs';
3
+ export { BrowserAdapter, HangulObfuscationLayer, createObfuscationLayer, createReadableDecodeStream, createReadableEncodeStream, detectRuntime, getAdapter } from './browser.cjs';
2
4
 
3
- declare enum DduSetSymbol {
4
- DDU = "ddu",
5
- DDU_V1 = "ddu_v1",
6
- ONECHARSET = "oneCharSet"
7
- }
8
- interface CharSetConfig {
9
- /** charset 식별 심볼 */
10
- symbol: DduSetSymbol;
11
- /** 인코딩에 사용할 문자 배열 (codaChar가 있으면 기본 문자 배열) */
12
- charSet: string[];
13
- /** 종성 문자 배열 (charSet × codaChar 조합으로 최종 charset 생성) */
14
- codaChar?: string[];
15
- /** 최대 필요 문자 수 */
16
- maxRequiredLength: number;
17
- /** 비트 길이 (log2) */
18
- bitLength: number;
19
- /** 패딩 문자 */
20
- paddingChar: string;
21
- /** 패딩 문자 반복 방식 사용 여부 */
22
- useRepeatPadding?: boolean;
23
- }
24
- /** 진행률 콜백 정보 */
25
- interface DduProgressInfo {
26
- /** 현재 처리된 바이트 수 (근사값) */
27
- processedBytes: number;
28
- /** 전체 바이트 수 */
29
- totalBytes: number;
30
- /** 진행률 (0-100, 단계별 근사값) */
31
- percent: number;
32
- /** 현재 처리 단계 */
33
- stage?: "start" | "encrypt" | "compress" | "encode" | "decode" | "decompress" | "checksum" | "decrypt" | "done";
34
- }
35
- /** 인코딩 통계 정보 */
36
- interface DduEncodeStats {
37
- /** 원본 데이터 크기 (바이트) */
38
- originalSize: number;
39
- /** 인코딩된 문자열 길이 */
40
- encodedSize: number;
41
- /** 압축된 크기 (압축 사용시) */
42
- compressedSize?: number;
43
- /** 압축률 (0-1, 낮을수록 효율적) */
44
- compressionRatio?: number;
45
- /** 인코딩 확장 비율 */
46
- expansionRatio: number;
47
- /** 사용된 charset 크기 */
48
- charsetSize: number;
49
- /** 비트 길이 */
50
- bitLength: number;
51
- }
52
- interface CharSetInfo {
53
- /** 인코딩에 사용할 문자 배열 */
54
- charSet: string[];
55
- /** 패딩 문자 */
56
- paddingChar: string;
57
- /** 비트 길이 */
58
- bitLength: number;
59
- /** 2의 제곱수 charset 여부 */
60
- usePowerOfTwo: boolean;
61
- /** 문자열 인코딩 방식 */
62
- encoding: BufferEncoding;
63
- /** 기본 압축 사용 여부 */
64
- defaultCompress: boolean;
65
- /** 기본 최대 디코딩 바이트 수 */
66
- defaultMaxDecodedBytes: number;
67
- /** 기본 최대 압축해제 바이트 수 */
68
- defaultMaxDecompressedBytes: number;
69
- /** URL-Safe 모드 여부 */
70
- urlSafe: boolean;
71
- /** 암호화 키 보유 여부 */
72
- hasEncryptionKey: boolean;
73
- /** 기본 체크섬 사용 여부 */
74
- defaultChecksum: boolean;
75
- /** 기본 청크 크기 */
76
- defaultChunkSize: number | undefined;
77
- /** 기본 청크 구분자 */
78
- defaultChunkSeparator: string;
79
- /** 기본 압축 레벨 */
80
- defaultCompressionLevel: number;
81
- /** 기본 압축 알고리즘 */
82
- defaultCompressionAlgorithm: "deflate" | "brotli";
83
- }
84
- interface DduOptions {
85
- /** 압축 사용 여부 (zlib deflate 또는 brotli) */
86
- compress?: boolean;
87
- /** decode stream에서 footer 기반 자동 감지 사용 여부 (기본값: true) */
88
- streamAutoDetect?: boolean;
89
- /** 내부 암/복호화 사용 여부 (기본값: true, 스트림 파이프라인 내부 제어용) */
90
- encrypt?: boolean;
91
- /** 압축 알고리즘 (기본값: "deflate") */
92
- compressionAlgorithm?: "deflate" | "brotli";
93
- /** 압축 레벨 (deflate 기본값: 6, brotli도 기본값 6을 사용하며 전달값은 0~11 범위로 보정) */
94
- compressionLevel?: number;
95
- /** 최대 디코딩 바이트 수 (Zip Bomb 방어) */
96
- maxDecodedBytes?: number;
97
- /** 최대 압축해제 바이트 수 (Zip Bomb 방어) */
98
- maxDecompressedBytes?: number;
99
- /** 체크섬 추가 여부 (CRC32) */
100
- checksum?: boolean;
101
- /** 청크 분할 크기 */
102
- chunkSize?: number;
103
- /** 청크 구분자 (기본값: '\n') */
104
- chunkSeparator?: string;
105
- /** 중간 스트림 청크처럼 푸터를 생략해야 할 때 사용 */
106
- omitFooter?: boolean;
107
- /** 진행률 콜백 */
108
- onProgress?: (info: DduProgressInfo) => void;
109
- }
110
- interface DduConstructorOptions extends DduOptions {
111
- /** 미리 정의된 charset 심볼 */
112
- dduSetSymbol?: DduSetSymbol;
113
- /** 커스텀 charset 문자 배열 또는 문자열 */
114
- dduChar?: string[] | string;
115
- /** 종성 문자 배열 (dduChar × codaChar 조합으로 최종 charset 동적 생성) */
116
- codaChar?: string[];
117
- /** 패딩 문자 */
118
- paddingChar?: string;
119
- /** 필요 문자 수 */
120
- requiredLength?: number;
121
- /** 비트 길이 */
122
- bitLength?: number;
123
- /** 2의 제곱수 강제 여부 */
124
- usePowerOfTwo?: boolean;
125
- /**
126
- * true이면 초기화 오류 시 throw합니다. false이면 fallback charset으로 대체합니다.
127
- * @default false
128
- * @deprecated throwOnError를 사용하세요. 이 옵션은 하위 호환성을 위해 유지됩니다.
129
- */
130
- useBuildErrorReturn?: boolean;
131
- /**
132
- * true이면 초기화 오류 시 throw합니다. false이면 fallback charset으로 대체합니다.
133
- * useBuildErrorReturn과 동일한 동작이며, 둘 다 지정 시 throwOnError가 우선합니다.
134
- * @default false
135
- */
136
- throwOnError?: boolean;
137
- /** Buffer 인코딩 방식 */
138
- encoding?: BufferEncoding;
139
- /** URL-Safe 모드 (특수문자를 URL 안전 문자로 변환) */
140
- urlSafe?: boolean;
141
- /** 암호화 키 (AES-256-GCM) */
142
- encryptionKey?: string;
143
- /** 패딩 문자 반복 방식 사용 여부 */
144
- useRepeatPadding?: boolean;
145
- }
146
-
147
- /**
148
- * AES-256-GCM 스트림 암호화 (Node.js Transform)
149
- */
150
- declare class GcmEncryptStream extends Transform {
151
- private cipher;
152
- constructor(keyHash: Buffer);
153
- _transform(chunk: Buffer, enc: BufferEncoding, cb: TransformCallback): void;
154
- _flush(cb: TransformCallback): void;
155
- }
156
5
  /**
157
- * AES-256-GCM 스트림 복호화 (Node.js Transform)
6
+ * Node.js 전용 Ddu64 래퍼.
7
+ *
8
+ * Ddu64Core를 확장하여 Node.js Buffer를 지원합니다:
9
+ * - NodeAdapter 자동 주입 (수동 어댑터 설정 불필요)
10
+ * - Node.js Buffer를 반환하는 `decodeToBuffer` 및 `decodeToBufferAsync` 제공
11
+ * - encode()에 Buffer 입력 허용 (Buffer는 Uint8Array를 확장)
12
+ *
13
+ * @module Ddu64Node
158
14
  */
159
- declare class GcmDecryptStream extends Transform {
160
- private keyHash;
161
- private iv;
162
- private decipher;
163
- private tail;
164
- constructor(keyHash: Buffer);
165
- _transform(chunk: Buffer, enc: BufferEncoding, cb: TransformCallback): void;
166
- _flush(cb: TransformCallback): void;
167
- }
168
15
 
169
16
  /**
170
- * 커스텀 charset을 사용하는 Base64 스타일 인코더
17
+ * Node.js 전용 Ddu64 인코더/디코더.
171
18
  *
172
- * @description
173
- * 바이너리 데이터를 지정된 charset으로 인코딩/디코딩합니다.
174
- * 2의 제곱수 charset과 가변 길이 charset 모두 지원하며,
175
- * 압축 옵션을 통해 데이터 크기를 줄일 수 있습니다.
19
+ * Ddu64Core를 래핑하여 자동 NodeAdapter 주입과
20
+ * 하위 호환성을 위한 Buffer 반환 디코드 메서드를 제공합니다.
176
21
  *
177
22
  * @example
178
- * // 기본 사용
179
- * const encoder = new Ddu64("우따야", "뭐");
180
- * const encoded = encoder.encode("Hello");
181
- * const decoded = encoder.decode(encoded);
23
+ * ```ts
24
+ * import { Ddu64Node } from './Ddu64Node';
182
25
  *
183
- * @example
184
- * // 압축 사용
185
- * const encoder = new Ddu64(undefined, undefined, { compress: true });
186
- * const encoded = encoder.encode(longText);
26
+ * const encoder = new Ddu64Node();
27
+ * const encoded = encoder.encode(Buffer.from('Hello'));
28
+ * const decoded = encoder.decodeToBuffer(encoded); // Buffer 반환
29
+ * ```
187
30
  */
188
- declare class Ddu64 {
189
- protected readonly defaultEncoding: BufferEncoding;
190
- /** 인코딩에 사용할 문자 배열 */
191
- protected readonly dduChar: string[];
192
- /** 패딩 문자 */
193
- protected readonly paddingChar: string;
194
- /** 비트 길이 (log2) */
195
- protected readonly bitLength: number;
196
- /** 2의 제곱수 charset 여부 */
197
- protected readonly usePowerOfTwo: boolean;
198
- /** 문자열 인코딩 방식 */
199
- protected readonly encoding: BufferEncoding;
200
- /** 기본 압축 사용 여부 */
201
- protected readonly defaultCompress: boolean;
202
- /** 기본 최대 디코딩 바이트 수 */
203
- private readonly defaultMaxDecodedBytes;
204
- /** 기본 최대 압축해제 바이트 수 */
205
- private readonly defaultMaxDecompressedBytes;
206
- /** 문자 → 인덱스 역방향 룩업 맵 */
207
- protected readonly dduBinaryLookup: Map<string, number>;
208
- /** 미리 정의된 charset 사용 여부 */
209
- private readonly isPredefinedCharSet;
210
- /** 실제 사용되는 비트 길이 */
211
- private readonly effectiveBitLength;
212
- /** 최대 바이너리 값 */
213
- private readonly maxBinaryValue;
214
- /** ASCII 문자 빠른 룩업 테이블 */
215
- private readonly fastAsciiLookup;
216
- /** ASCII 룩업 사용 여부 */
217
- private readonly useAsciiLookup;
218
- /** URL-Safe 모드 여부 */
219
- private readonly urlSafe;
220
- /** 암호화 키 해시 (AES-256용 32바이트) */
221
- private readonly encryptionKeyHash;
222
- /** 기본 체크섬 사용 여부 */
223
- private readonly defaultChecksum;
224
- /** 기본 청크 크기 */
225
- private readonly defaultChunkSize;
226
- /** 기본 청크 구분자 */
227
- private readonly defaultChunkSeparator;
228
- /** 기본 압축 레벨 (1~9) */
229
- private readonly defaultCompressionLevel;
230
- /** 기본 압축 알고리즘 */
231
- private readonly defaultCompressionAlgorithm;
232
- /** 패딩 문자 반복 방식 사용 여부 */
233
- private readonly useRepeatPadding;
234
- /**
235
- * Ddu64 인코더 인스턴스를 생성합니다.
236
- *
237
- * @param dduChar - charset 문자열 또는 배열 (미지정 시 옵션의 dduSetSymbol 사용)
238
- * @param paddingChar - 패딩 문자 (dduChar 지정 시 필수)
239
- * @param dduOptions - 생성자 옵션
240
- *
241
- * @throws dduChar 지정 시 paddingChar가 없으면 에러
242
- * @throws charset 문자 수가 부족하면 에러
243
- *
244
- * @example
245
- * // 커스텀 charset
246
- * new Ddu64("우따야", "뭐");
247
- *
248
- * @example
249
- * // 미리 정의된 charset
250
- * new Ddu64(undefined, undefined, { dduSetSymbol: DduSetSymbol.ONECHARSET });
251
- */
31
+ declare class Ddu64Node extends Ddu64Core {
252
32
  constructor(dduChar?: string[] | string, paddingChar?: string, dduOptions?: DduConstructorOptions);
253
33
  /**
254
- * 입력 데이터를 인코딩합니다.
255
- *
256
- * @param input - 인코딩할 문자열 또는 Buffer
257
- * @param options - 인코딩 옵션
258
- * @param options.compress - 압축 사용 여부 (기본값: 생성자 설정)
259
- * @param options.checksum - 체크섬 추가 여부
260
- * @param options.chunkSize - 청크 분할 크기
261
- * @param options.chunkSeparator - 청크 구분자
262
- * @param options.onProgress - 진행률 콜백
263
- * @returns 인코딩된 문자열
264
- *
265
- * @example
266
- * encoder.encode("Hello World!");
267
- * encoder.encode(buffer, { compress: true });
268
- * encoder.encode(data, { checksum: true, chunkSize: 76 });
269
- */
270
- encode(input: Buffer | string, options?: DduOptions): string;
271
- /**
272
- * 인코딩 핵심 로직. encode()와 getStats()가 공유합니다.
273
- * 압축 크기 등 메타데이터도 함께 반환하여 중복 deflateSync 호출을 방지합니다.
274
- */
275
- private encodeInternal;
276
- /**
277
- * 인코딩된 문자열을 Buffer로 디코딩합니다.
34
+ * 인코딩된 문자열을 Node.js Buffer로 디코딩합니다.
278
35
  *
279
36
  * @param input - 디코딩할 인코딩된 문자열
280
37
  * @param options - 디코딩 옵션
281
- * @param options.maxDecodedBytes - 최대 디코딩 바이트 수
282
- * @param options.maxDecompressedBytes - 최대 압축해제 바이트 수
283
- * @param options.onProgress - 진행률 콜백
284
38
  * @returns 디코딩된 Buffer
285
- *
286
- * @throws 잘못된 문자가 포함된 경우
287
- * @throws 패딩 형식이 잘못된 경우
288
- * @throws 크기 제한 초과 시
289
- * @throws 체크섬 불일치 시
290
39
  */
291
40
  decodeToBuffer(input: string, options?: DduOptions): Buffer;
292
41
  /**
293
- * 인코딩된 문자열을 원본 문자열로 디코딩합니다.
294
- *
295
- * @param input - 디코딩할 인코딩된 문자열
296
- * @param options - 디코딩 옵션
297
- * @returns 디코딩된 문자열
298
- *
299
- * @throws 잘못된 문자나 패딩 형식일 경우 에러
300
- */
301
- decode(input: string, options?: DduOptions): string;
302
- /**
303
- * @internal
304
- * 공개 스트림 API의 auto-detect 경로에서 사용하는 전용 디코더입니다.
305
- * 스트림 인코딩은 compress -> encrypt -> encode 순서를 사용하므로,
306
- * 복원은 decode -> decrypt -> decompress 순서로 수행합니다.
307
- */
308
- decodeStreamToBuffer(input: string, options?: DduOptions): Buffer;
309
- /**
310
- * 공통 디코딩 로직: footer 파싱 → 정렬 검증 → 크기 검증 → decodeFast
311
- */
312
- private decodeRaw;
313
- /**
314
- * 현재 인코더의 charset 정보를 반환합니다.
315
- *
316
- * @returns charset 설정 정보 객체
317
- */
318
- getCharSetInfo(): CharSetInfo;
319
- /**
320
- * @internal
321
- * 외부 스트림 파이프라인에서 전처리된 Buffer를 그대로 인코딩합니다.
322
- * 압축/암호화는 수행하지 않고, 마지막 푸터에만 메타데이터를 반영합니다.
323
- */
324
- encodeRawBuffer(input: Buffer, options?: {
325
- compressionAlgorithm?: "deflate" | "brotli";
326
- encrypted?: boolean;
327
- omitFooter?: boolean;
328
- }): string;
329
- /**
330
- * 인코딩 통계 정보를 반환합니다.
331
- *
332
- * @param input - 분석할 데이터
333
- * @param options - 인코딩 옵션
334
- * @returns 통계 정보 객체
335
- */
336
- getStats(input: Buffer | string, options?: DduOptions): DduEncodeStats;
337
- /**
338
- * 비동기 인코딩을 수행합니다.
339
- *
340
- * 가능한 경우 청크 단위로 Event Loop를 양보(Yield)하여 스타베이션을 줄입니다.
341
- * 다만 압축, 체크섬, 암호화, URL-safe가 개입되는 큰 입력은 정확성을 위해
342
- * 안전한 단일 페이로드 경로로 fallback 됩니다.
343
- *
344
- * @param input - 인코딩할 데이터
345
- * @param options - 인코딩 옵션
346
- * @returns 인코딩된 문자열 Promise
347
- */
348
- encodeAsync(input: Buffer | string, options?: DduOptions): Promise<string>;
349
- /**
350
- * 비동기 디코딩을 수행합니다.
351
- *
352
- * 대용량 데이터를 처리할 때 Event Loop를 양보하여 블로킹을 방지합니다.
353
- *
354
- * @param input - 디코딩할 인코딩된 문자열
355
- * @param options - 디코딩 옵션
356
- * @returns 디코딩된 문자열 Promise
357
- */
358
- decodeAsync(input: string, options?: DduOptions): Promise<string>;
359
- /**
360
- * 비동기 디코딩을 Buffer로 수행합니다.
42
+ * 비동기적으로 Node.js Buffer로 디코딩합니다.
361
43
  *
362
44
  * @param input - 디코딩할 인코딩된 문자열
363
45
  * @param options - 디코딩 옵션
364
- * @returns 디코딩된 Buffer Promise
365
- *
366
- * @description
367
- * 큰 입력 중에서도 압축, 암호화, 체크섬, 청크 구분자 해석이 필요한 경우에는
368
- * 안전성을 위해 내부적으로 전체 페이로드 단위 디코딩으로 fallback 될 수 있습니다.
46
+ * @returns 디코딩된 Buffer resolve되는 Promise
369
47
  */
370
48
  decodeToBufferAsync(input: string, options?: DduOptions): Promise<Buffer>;
371
- /**
372
- * 데이터를 AES-256-GCM으로 암호화합니다.
373
- */
374
- private encryptData;
375
- /**
376
- * AES-256-GCM으로 암호화된 데이터를 복호화합니다.
377
- */
378
- private decryptData;
379
- /**
380
- * 공개 스트림 API의 암호화 포맷(iv + encrypted + authTag)을 복호화합니다.
381
- */
382
- private decryptStreamData;
383
- /**
384
- * @internal
385
- * 공개 스트림 API에서 사용할 암호화 Transform을 생성합니다.
386
- */
387
- createEncryptionStream(): GcmEncryptStream | undefined;
388
- /**
389
- * @internal
390
- * 공개 스트림 API에서 사용할 복호화 Transform을 생성합니다.
391
- */
392
- createDecryptionStream(): GcmDecryptStream | undefined;
393
- /**
394
- * 주어진 숫자보다 작거나 같은 가장 큰 2의 제곱수의 지수를 반환합니다.
395
- */
396
- private getLargestPowerOfTwoExponent;
397
- /**
398
- * charset 크기에 필요한 비트 길이를 계산합니다.
399
- */
400
- private getBitLength;
401
- /**
402
- * 옵션 값을 정규화합니다.
403
- */
404
- private normalizeLimit;
405
- /**
406
- * 디코딩 결과 바이트 수를 추정합니다.
407
- */
408
- private estimateDecodedBytes;
409
- /**
410
- * 인코딩된 입력의 정렬을 검증합니다.
411
- */
412
- private assertEncodedInputAligned;
413
- /**
414
- * 크기 제한을 적용하여 압축을 해제합니다.
415
- */
416
- private inflateWithLimit;
417
- /**
418
- * 인코딩된 문자열의 푸터(패딩 정보)를 파싱합니다.
419
- *
420
- * 푸터 형식: {encodedData}{paddingChar}[ELYSIA][ENC]{digits}
421
- * 끝에서부터 역순으로 파싱하여 paddingChar가 숫자인 경우도 안전하게 처리합니다.
422
- */
423
- private parseFooter;
424
- /**
425
- * 일반 정수 연산을 사용한 빠른 인코딩
426
- */
427
- private encodeFast;
428
- /**
429
- * 일반 정수 연산을 사용한 빠른 디코딩
430
- */
431
- private decodeFast;
432
- /**
433
- * 인코딩 파트 배열을 최종 문자열로 직렬화합니다.
434
- * 청크 옵션이 있으면 join 후 split하는 대신 한 번에 separator를 삽입합니다.
435
- */
436
- private serializeEncodedParts;
437
- /**
438
- * Charset을 정규화합니다.
439
- */
440
- private normalizeCharSet;
441
- /**
442
- * 초기 charset을 결정합니다.
443
- */
444
- private resolveInitialCharSet;
445
- /**
446
- * Fallback charset을 반환합니다.
447
- */
448
- private getFallbackCharSet;
449
- /**
450
- * 2의 제곱수 사용 여부를 결정합니다.
451
- */
452
- private shouldUsePowerOfTwo;
453
- /**
454
- * charset을 가져오거나 에러를 발생시킵니다.
455
- */
456
- private getCharSetOrThrow;
457
- /**
458
- * URL-Safe 모드 시 charset/padding이 역변환 대상 문자를 포함하지 않는지 검증합니다.
459
- * 역변환 대상 문자("-", "_", ".")가 charset이나 padding에 있으면
460
- * fromUrlSafe 시 해당 문자가 "+", "/", "="로 변환되어 데이터가 손상됩니다.
461
- *
462
- * @returns URL-Safe 모드를 활성화해도 안전한 경우 true
463
- */
464
- private isUrlSafeCompatible;
465
- /**
466
- * 커스텀 charset의 조합 중복을 검증합니다.
467
- */
468
- private validateCombinationDuplicates;
469
49
  }
470
50
 
471
51
  /**
472
- * 커스텀 Charset을 쉽게 생성하기 위한 빌더 클래스
52
+ * Node.js 플랫폼 어댑터 구현.
53
+ * Node.js `crypto`와 `zlib` 모듈을 래핑하여 PlatformAdapter 인터페이스를 구현합니다.
473
54
  *
474
- * @example
475
- * const chars = CharsetBuilder
476
- * .fromUnicodeRange(0x4E00, 0x4E3F)
477
- * .excludeConfusing()
478
- * .shuffle()
479
- * .build();
55
+ * @module adapters/NodeAdapter
480
56
  */
481
- declare class CharsetBuilder {
482
- private chars;
483
- private constructor();
484
- /**
485
- * 빈 빌더를 생성합니다.
486
- */
487
- static create(): CharsetBuilder;
488
- /**
489
- * 유니코드 범위에서 문자들을 추가합니다.
490
- *
491
- * @param start - 시작 유니코드 코드포인트
492
- * @param end - 끝 유니코드 코드포인트 (포함)
493
- */
494
- static fromUnicodeRange(start: number, end: number): CharsetBuilder;
495
- /**
496
- * 문자열에서 문자들을 추가합니다.
497
- *
498
- * @param chars - 문자열 또는 문자 배열
499
- */
500
- static fromString(chars: string | string[]): CharsetBuilder;
501
- /**
502
- * Base64 표준 문자셋으로 시작합니다.
503
- */
504
- static base64(): CharsetBuilder;
505
- /**
506
- * Base32 표준 문자셋으로 시작합니다.
507
- */
508
- static base32(): CharsetBuilder;
509
- /**
510
- * 영문 대문자만 포함합니다.
511
- */
512
- static uppercase(): CharsetBuilder;
513
- /**
514
- * 영문 소문자만 포함합니다.
515
- */
516
- static lowercase(): CharsetBuilder;
517
- /**
518
- * 숫자만 포함합니다.
519
- */
520
- static digits(): CharsetBuilder;
521
- /**
522
- * 한글 자모를 포함합니다.
523
- */
524
- static hangulJamo(): CharsetBuilder;
525
- /**
526
- * 유니코드 범위에서 문자들을 추가합니다.
527
- */
528
- addUnicodeRange(start: number, end: number): CharsetBuilder;
529
- /**
530
- * 문자열에서 문자들을 추가합니다.
531
- */
532
- addString(chars: string | string[]): CharsetBuilder;
533
- /**
534
- * 특정 문자들을 추가합니다.
535
- */
536
- add(...chars: string[]): CharsetBuilder;
537
- /**
538
- * 혼동하기 쉬운 문자들을 제거합니다.
539
- * (0, O, o, 1, l, I, i 등)
540
- */
541
- excludeConfusing(): CharsetBuilder;
542
- /**
543
- * 특정 문자들을 제거합니다.
544
- */
545
- exclude(...chars: string[]): CharsetBuilder;
546
- /**
547
- * URL에서 안전하지 않은 문자들을 제거합니다.
548
- */
549
- excludeUrlUnsafe(): CharsetBuilder;
550
- /**
551
- * 중복 문자를 제거합니다.
552
- */
553
- unique(): CharsetBuilder;
554
- /**
555
- * 문자셋을 무작위로 섞습니다.
556
- */
557
- shuffle(seed?: number): CharsetBuilder;
558
- /**
559
- * 시드 기반 난수 생성기 (xorshift32)
560
- */
561
- private seededRandom;
562
- /**
563
- * 특정 길이로 자릅니다.
564
- */
565
- limit(length: number): CharsetBuilder;
566
- /**
567
- * 2의 제곱수 길이로 자릅니다.
568
- */
569
- limitToPowerOfTwo(): CharsetBuilder;
570
- /**
571
- * 문자셋을 정렬합니다.
572
- */
573
- sort(): CharsetBuilder;
574
- /**
575
- * 역순으로 정렬합니다.
576
- */
577
- reverse(): CharsetBuilder;
578
- /**
579
- * 현재 문자 수를 반환합니다.
580
- */
581
- get length(): number;
582
- /**
583
- * 문자셋을 문자열로 빌드합니다.
584
- */
585
- buildString(): string;
586
- /**
587
- * 문자셋을 배열로 빌드합니다.
588
- */
589
- build(): string[];
590
- /**
591
- * 문자셋과 패딩 문자를 함께 빌드합니다.
592
- *
593
- * @param paddingChar - 패딩 문자 (기본값: charset에서 제외된 첫 번째 문자)
594
- */
595
- buildWithPadding(paddingChar?: string): {
596
- charset: string[];
597
- padding: string;
598
- };
599
- }
600
57
 
601
58
  /**
602
- * 다중 인코딩/암호화/압축을 파이프라인으로 조합할 수 있는 빌더 클래스
603
- *
604
- * @example
605
- * const pipeline = new DduPipeline()
606
- * .compress()
607
- * .encrypt('secret-key')
608
- * .encode(new Ddu64(chars, pad));
609
- *
610
- * const encoded = pipeline.process('Hello World');
611
- * const decoded = pipeline.reverse().process(encoded);
59
+ * PlatformAdapter의 Node.js 구현.
60
+ * 네이티브 Node.js `crypto`와 `zlib` 모듈을 사용하여
61
+ * 동기 및 비동기 암호화/압축 연산을 제공합니다.
612
62
  */
613
- declare class DduPipeline {
614
- private steps;
615
- /**
616
- * 압축 단계를 추가합니다.
617
- *
618
- * @param level - 압축 레벨 (0-9, 기본값: 9)
619
- * @param algorithm - 압축 알고리즘 (기본값: "deflate")
620
- */
621
- compress(level?: number, algorithm?: "deflate" | "brotli"): DduPipeline;
622
- /**
623
- * 압축 해제 단계를 추가합니다.
624
- *
625
- * @param maxDecompressedBytes - 최대 압축해제 바이트 수 (Zip Bomb 방어용)
626
- * @param algorithm - 압축 알고리즘 (기본값: "deflate")
627
- */
628
- decompress(maxDecompressedBytes?: number, algorithm?: "deflate" | "brotli"): DduPipeline;
629
- /**
630
- * AES-256-GCM 암호화 단계를 추가합니다.
631
- *
632
- * @param key - 암호화 키
633
- */
634
- encrypt(key: string): DduPipeline;
635
- /**
636
- * AES-256-GCM 복호화 단계를 추가합니다.
637
- *
638
- * @param key - 복호화 키
639
- */
640
- decrypt(key: string): DduPipeline;
641
- /**
642
- * Ddu64 인코딩 단계를 추가합니다.
643
- *
644
- * @param encoder - Ddu64 인코더 인스턴스
645
- */
646
- encode(encoder: Ddu64): DduPipeline;
647
- /**
648
- * Ddu64 디코딩 단계를 추가합니다.
649
- *
650
- * @param encoder - Ddu64 인코더 인스턴스
651
- */
652
- decode(encoder: Ddu64): DduPipeline;
653
- /**
654
- * 새 인코더를 생성하여 인코딩 단계를 추가합니다.
655
- *
656
- * @param dduChar - charset 문자열 또는 배열
657
- * @param paddingChar - 패딩 문자
658
- * @param options - 인코더 옵션
659
- */
660
- encodeWith(dduChar?: string[] | string, paddingChar?: string, options?: DduConstructorOptions): DduPipeline;
661
- /**
662
- * 커스텀 Buffer 변환 단계를 추가합니다.
663
- *
664
- * @param fn - 변환 함수
665
- */
666
- transform(fn: (data: Buffer) => Buffer): DduPipeline;
667
- /**
668
- * 커스텀 문자열 변환 단계를 추가합니다.
669
- *
670
- * @param fn - 변환 함수
671
- */
672
- transformString(fn: (data: string) => string): DduPipeline;
673
- /**
674
- * 파이프라인을 역순으로 실행할 새 파이프라인을 생성합니다.
675
- */
676
- reverse(): DduPipeline;
677
- /**
678
- * 파이프라인을 실행합니다.
679
- *
680
- * @param input - 입력 데이터 (문자열 또는 Buffer)
681
- * @returns 처리된 결과 (문자열 또는 Buffer)
682
- */
683
- process(input: string | Buffer): string | Buffer;
684
- /**
685
- * 파이프라인을 실행하고 문자열로 반환합니다.
686
- */
687
- processToString(input: string | Buffer, encoding?: BufferEncoding): string;
688
- /**
689
- * 파이프라인을 실행하고 Buffer로 반환합니다.
690
- */
691
- processToBuffer(input: string | Buffer, encoding?: BufferEncoding): Buffer;
692
- /**
693
- * 개별 단계를 실행합니다.
694
- */
695
- private executeStep;
696
- private toBuffer;
697
- private toString;
698
- private compressData;
699
- private decompressData;
700
- private encryptData;
701
- private decryptData;
702
- /**
703
- * 현재 파이프라인의 단계 수를 반환합니다.
704
- */
705
- get stepCount(): number;
706
- /**
707
- * 파이프라인을 복제합니다.
708
- */
709
- clone(): DduPipeline;
710
- /**
711
- * 파이프라인을 초기화합니다.
712
- */
713
- clear(): DduPipeline;
63
+ declare class NodeAdapter implements PlatformAdapter {
64
+ readonly supportsSyncCrypto = true;
65
+ readonly supportsSyncCompression = true;
66
+ readonly supportsBrotli = true;
67
+ readonly runtime: "node";
68
+ deriveKey(key: string, options?: KeyDerivationOptions): Promise<Uint8Array>;
69
+ deriveKeySync(key: string, options?: KeyDerivationOptions): Uint8Array;
70
+ encrypt(data: Uint8Array, keyHash: Uint8Array): Promise<Uint8Array>;
71
+ encryptSync(data: Uint8Array, keyHash: Uint8Array): Uint8Array;
72
+ decrypt(data: Uint8Array, keyHash: Uint8Array): Promise<Uint8Array>;
73
+ decryptSync(data: Uint8Array, keyHash: Uint8Array): Uint8Array;
74
+ randomBytes(length: number): Uint8Array;
75
+ deflate(data: Uint8Array, level?: number): Promise<Uint8Array>;
76
+ deflateSync(data: Uint8Array, level?: number): Uint8Array;
77
+ inflate(data: Uint8Array, maxBytes?: number): Promise<Uint8Array>;
78
+ inflateSync(data: Uint8Array, maxBytes?: number): Uint8Array;
79
+ brotliCompress(data: Uint8Array, level?: number): Promise<Uint8Array>;
80
+ brotliCompressSync(data: Uint8Array, level?: number): Uint8Array;
81
+ brotliDecompress(data: Uint8Array, maxBytes?: number): Promise<Uint8Array>;
82
+ brotliDecompressSync(data: Uint8Array, maxBytes?: number): Uint8Array;
714
83
  }
715
84
 
716
85
  /**
717
- * Ddu64 인코딩을 위한 Transform 스트림
718
- * (내부적으로 청크 단위 인코딩을 수행합니다. 압축이 필요한 경우
719
- * `createEncodeStream` 팩토리 함수를 사용하는 것을 권장합니다.)
86
+ * 인코딩/디코딩 연산을 워커 스레드로 오프로드하는 워커 풀 관리자.
720
87
  *
721
- * @example
722
- * const encoder = new Ddu64(chars, pad);
723
- * const stream = new DduEncodeStream(encoder);
724
- * fs.createReadStream('input.bin')
725
- * .pipe(stream)
726
- * .pipe(fs.createWriteStream('output.txt'));
727
- */
728
- declare class DduEncodeStream extends Transform {
729
- private encoder;
730
- private buffers;
731
- private bufferOffset;
732
- private totalLength;
733
- private chunkSize;
734
- private footerCompressionAlgorithm;
735
- private footerEncrypted;
736
- constructor(encoder: Ddu64, options?: DduOptions & TransformOptions);
737
- /**
738
- * 비트 길이에 맞는 최적의 청크 크기를 계산합니다.
739
- */
740
- private calculateChunkSize;
741
- _transform(chunk: Buffer, _encoding: BufferEncoding, callback: TransformCallback): void;
742
- _flush(callback: TransformCallback): void;
743
- private encodeChunk;
744
- private readBytes;
745
- }
746
- /**
747
- * Ddu64 디코딩을 위한 Transform 스트림
748
- * (내부적으로 청크 단위 디코딩을 수행합니다. 압축 해제가 필요한 경우
749
- * `createDecodeStream` 팩토리 함수를 사용하는 것을 권장합니다.)
88
+ * Node.js Worker Threads와 Web Workers를 모두 지원합니다.
89
+ * 라운드 로빈 태스크 분배와 지연 초기화를 사용합니다.
750
90
  *
751
- * @example
752
- * const encoder = new Ddu64(chars, pad);
753
- * const stream = new DduDecodeStream(encoder);
754
- * fs.createReadStream('input.txt')
755
- * .pipe(stream)
756
- * .pipe(fs.createWriteStream('output.bin'));
757
- */
758
- declare class DduDecodeStream extends Transform {
759
- private encoder;
760
- private options;
761
- private normalizedBuffer;
762
- private chunkSize;
763
- private chunkSeparator;
764
- private separatorTail;
765
- constructor(encoder: Ddu64, options?: DduOptions & TransformOptions);
766
- _transform(chunk: Buffer, _encoding: BufferEncoding, callback: TransformCallback): void;
767
- _flush(callback: TransformCallback): void;
768
- private appendNormalizedChunk;
769
- }
770
- /**
771
- * Ddu64 인코더에서 스트림을 생성하는 팩토리 함수
772
- * 옵션에 따라 압축 스트림을 자동으로 연결합니다.
91
+ * @module workers/WorkerPool
773
92
  */
774
- declare function createEncodeStream(encoder: Ddu64, options?: DduOptions & TransformOptions): NodeJS.ReadWriteStream;
93
+
775
94
  /**
776
- * Ddu64 인코더에서 디코드 스트림을 생성하는 팩토리 함수
777
- * 옵션에 따라 압축 해제 스트림을 자동으로 연결합니다.
778
- * 기본적으로 footer를 끝까지 읽어 압축/암호화를 자동 감지합니다.
779
- * 진짜 스트리밍 복원을 원하면 `streamAutoDetect: false`와 함께 encode 측과 동일한
780
- * compress/encryption 설정 또는 같은 encoder 기본값을 사용해야 합니다.
95
+ * 전역 워커 크기를 설정합니다.
96
+ * `Ddu64.setWorkerPoolSize(n)`을 통해 노출되는 함수입니다.
97
+ *
98
+ * @param n - 워커 (정수, 1–64)
99
+ * @throws n이 정수가 아니거나 범위를 벗어난 경우 에러
781
100
  */
782
- declare function createDecodeStream(encoder: Ddu64, options?: DduOptions & TransformOptions): NodeJS.ReadWriteStream;
101
+ declare function setWorkerPoolSize(n: number): void;
783
102
 
784
- export { type CharSetConfig, type CharSetInfo, CharsetBuilder, Ddu64, type DduConstructorOptions, DduDecodeStream, type DduEncodeStats, DduEncodeStream, type DduOptions, DduPipeline, type DduProgressInfo, DduSetSymbol, createDecodeStream, createEncodeStream };
103
+ export { Ddu64Node as Ddu64, Ddu64Core, Ddu64Node, DduConstructorOptions, DduOptions, KeyDerivationOptions, NodeAdapter, PlatformAdapter, setWorkerPoolSize };