@digitaldefiance/node-ecies-lib 1.1.20 → 1.1.22
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 +8 -0
- package/package.json +14 -35
- package/src/constants.ts +182 -0
- package/src/enumerations/index.ts +1 -0
- package/src/enumerations/pbkdf2-profile.ts +8 -0
- package/src/i18n/ecies-i18n-factory.ts +435 -0
- package/{dist/i18n/index.d.ts → src/i18n/index.ts} +0 -1
- package/{dist/index.d.ts → src/index.ts} +0 -1
- package/src/interfaces/authenticated-cipher.ts +9 -0
- package/src/interfaces/authenticated-decipher.ts +8 -0
- package/src/interfaces/checksum-config.ts +4 -0
- package/src/interfaces/checksum-consts.ts +13 -0
- package/src/interfaces/constants.ts +43 -0
- package/src/interfaces/ecies-consts.ts +99 -0
- package/src/interfaces/encryption-consts.ts +10 -0
- package/{dist/interfaces/index.d.ts → src/interfaces/index.ts} +0 -1
- package/src/interfaces/keypair-buffer-with-un-encrypted-private-key.ts +7 -0
- package/src/interfaces/keyring-consts.ts +5 -0
- package/src/interfaces/member-operational.ts +52 -0
- package/{dist/interfaces/member-with-mnemonic.d.ts → src/interfaces/member-with-mnemonic.ts} +3 -3
- package/{dist/interfaces/multi-encrypted-message.d.ts → src/interfaces/multi-encrypted-message.ts} +5 -5
- package/src/interfaces/multi-encrypted-parsed-header.ts +24 -0
- package/{dist/interfaces/pbkdf-profiles.d.ts → src/interfaces/pbkdf-profiles.ts} +2 -2
- package/src/interfaces/pbkdf2-result.ts +5 -0
- package/src/interfaces/signing-key-private-key-info.ts +12 -0
- package/{dist/interfaces/simple-keypair-buffer.d.ts → src/interfaces/simple-keypair-buffer.ts} +3 -3
- package/{dist/interfaces/simple-keypair.d.ts → src/interfaces/simple-keypair.ts} +3 -3
- package/src/interfaces/simple-public-key-only-buffer.ts +3 -0
- package/src/interfaces/simple-public-key-only.ts +3 -0
- package/src/interfaces/single-encrypted-parsed-header.ts +35 -0
- package/{dist/interfaces/wallet-seed.d.ts → src/interfaces/wallet-seed.ts} +3 -3
- package/src/interfaces/wrapped-key-consts.ts +6 -0
- package/src/member.ts +463 -0
- package/src/services/aes-gcm.ts +160 -0
- package/src/services/ecies/crypto-core.ts +213 -0
- package/src/services/ecies/file.ts +174 -0
- package/{dist/services/ecies/index.d.ts → src/services/ecies/index.ts} +0 -1
- package/src/services/ecies/multi-recipient.ts +583 -0
- package/src/services/ecies/service.ts +351 -0
- package/src/services/ecies/signature.ts +91 -0
- package/src/services/ecies/single-recipient.ts +676 -0
- package/src/services/ecies/utilities.ts +111 -0
- package/src/services/index.ts +3 -0
- package/src/services/pbkdf2.ts +307 -0
- package/{dist/types.d.ts → src/types.ts} +26 -9
- package/src/utils.ts +104 -0
- package/dist/constants.d.ts +0 -32
- package/dist/constants.d.ts.map +0 -1
- package/dist/constants.js +0 -137
- package/dist/constants.js.map +0 -1
- package/dist/enumerations/index.d.ts +0 -2
- package/dist/enumerations/index.d.ts.map +0 -1
- package/dist/enumerations/index.js +0 -18
- package/dist/enumerations/index.js.map +0 -1
- package/dist/enumerations/pbkdf2-profile.d.ts +0 -9
- package/dist/enumerations/pbkdf2-profile.d.ts.map +0 -1
- package/dist/enumerations/pbkdf2-profile.js +0 -13
- package/dist/enumerations/pbkdf2-profile.js.map +0 -1
- package/dist/i18n/ecies-i18n-factory.d.ts +0 -54
- package/dist/i18n/ecies-i18n-factory.d.ts.map +0 -1
- package/dist/i18n/ecies-i18n-factory.js +0 -332
- package/dist/i18n/ecies-i18n-factory.js.map +0 -1
- package/dist/i18n/index.d.ts.map +0 -1
- package/dist/i18n/index.js +0 -18
- package/dist/i18n/index.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -24
- package/dist/index.js.map +0 -1
- package/dist/interfaces/authenticated-cipher.d.ts +0 -10
- package/dist/interfaces/authenticated-cipher.d.ts.map +0 -1
- package/dist/interfaces/authenticated-cipher.js +0 -3
- package/dist/interfaces/authenticated-cipher.js.map +0 -1
- package/dist/interfaces/authenticated-decipher.d.ts +0 -9
- package/dist/interfaces/authenticated-decipher.d.ts.map +0 -1
- package/dist/interfaces/authenticated-decipher.js +0 -3
- package/dist/interfaces/authenticated-decipher.js.map +0 -1
- package/dist/interfaces/checksum-config.d.ts +0 -5
- package/dist/interfaces/checksum-config.d.ts.map +0 -1
- package/dist/interfaces/checksum-config.js +0 -3
- package/dist/interfaces/checksum-config.js.map +0 -1
- package/dist/interfaces/checksum-consts.d.ts +0 -11
- package/dist/interfaces/checksum-consts.d.ts.map +0 -1
- package/dist/interfaces/checksum-consts.js +0 -3
- package/dist/interfaces/checksum-consts.js.map +0 -1
- package/dist/interfaces/constants.d.ts +0 -43
- package/dist/interfaces/constants.d.ts.map +0 -1
- package/dist/interfaces/constants.js +0 -3
- package/dist/interfaces/constants.js.map +0 -1
- package/dist/interfaces/ecies-consts.d.ts +0 -88
- package/dist/interfaces/ecies-consts.d.ts.map +0 -1
- package/dist/interfaces/ecies-consts.js +0 -3
- package/dist/interfaces/ecies-consts.js.map +0 -1
- package/dist/interfaces/encryption-consts.d.ts +0 -11
- package/dist/interfaces/encryption-consts.d.ts.map +0 -1
- package/dist/interfaces/encryption-consts.js +0 -3
- package/dist/interfaces/encryption-consts.js.map +0 -1
- package/dist/interfaces/index.d.ts.map +0 -1
- package/dist/interfaces/index.js +0 -34
- package/dist/interfaces/index.js.map +0 -1
- package/dist/interfaces/keypair-buffer-with-un-encrypted-private-key.d.ts +0 -6
- package/dist/interfaces/keypair-buffer-with-un-encrypted-private-key.d.ts.map +0 -1
- package/dist/interfaces/keypair-buffer-with-un-encrypted-private-key.js +0 -3
- package/dist/interfaces/keypair-buffer-with-un-encrypted-private-key.js.map +0 -1
- package/dist/interfaces/keyring-consts.d.ts +0 -6
- package/dist/interfaces/keyring-consts.d.ts.map +0 -1
- package/dist/interfaces/keyring-consts.js +0 -3
- package/dist/interfaces/keyring-consts.js.map +0 -1
- package/dist/interfaces/member-operational.d.ts +0 -36
- package/dist/interfaces/member-operational.d.ts.map +0 -1
- package/dist/interfaces/member-operational.js +0 -3
- package/dist/interfaces/member-operational.js.map +0 -1
- package/dist/interfaces/member-with-mnemonic.d.ts.map +0 -1
- package/dist/interfaces/member-with-mnemonic.js +0 -3
- package/dist/interfaces/member-with-mnemonic.js.map +0 -1
- package/dist/interfaces/multi-encrypted-message.d.ts.map +0 -1
- package/dist/interfaces/multi-encrypted-message.js +0 -3
- package/dist/interfaces/multi-encrypted-message.js.map +0 -1
- package/dist/interfaces/multi-encrypted-parsed-header.d.ts +0 -24
- package/dist/interfaces/multi-encrypted-parsed-header.d.ts.map +0 -1
- package/dist/interfaces/multi-encrypted-parsed-header.js +0 -3
- package/dist/interfaces/multi-encrypted-parsed-header.js.map +0 -1
- package/dist/interfaces/pbkdf-profiles.d.ts.map +0 -1
- package/dist/interfaces/pbkdf-profiles.js +0 -3
- package/dist/interfaces/pbkdf-profiles.js.map +0 -1
- package/dist/interfaces/pbkdf2-result.d.ts +0 -6
- package/dist/interfaces/pbkdf2-result.d.ts.map +0 -1
- package/dist/interfaces/pbkdf2-result.js +0 -3
- package/dist/interfaces/pbkdf2-result.js.map +0 -1
- package/dist/interfaces/signing-key-private-key-info.d.ts +0 -11
- package/dist/interfaces/signing-key-private-key-info.d.ts.map +0 -1
- package/dist/interfaces/signing-key-private-key-info.js +0 -3
- package/dist/interfaces/signing-key-private-key-info.js.map +0 -1
- package/dist/interfaces/simple-keypair-buffer.d.ts.map +0 -1
- package/dist/interfaces/simple-keypair-buffer.js +0 -3
- package/dist/interfaces/simple-keypair-buffer.js.map +0 -1
- package/dist/interfaces/simple-keypair.d.ts.map +0 -1
- package/dist/interfaces/simple-keypair.js +0 -3
- package/dist/interfaces/simple-keypair.js.map +0 -1
- package/dist/interfaces/simple-public-key-only-buffer.d.ts +0 -4
- package/dist/interfaces/simple-public-key-only-buffer.d.ts.map +0 -1
- package/dist/interfaces/simple-public-key-only-buffer.js +0 -3
- package/dist/interfaces/simple-public-key-only-buffer.js.map +0 -1
- package/dist/interfaces/simple-public-key-only.d.ts +0 -4
- package/dist/interfaces/simple-public-key-only.d.ts.map +0 -1
- package/dist/interfaces/simple-public-key-only.js +0 -3
- package/dist/interfaces/simple-public-key-only.js.map +0 -1
- package/dist/interfaces/single-encrypted-parsed-header.d.ts +0 -35
- package/dist/interfaces/single-encrypted-parsed-header.d.ts.map +0 -1
- package/dist/interfaces/single-encrypted-parsed-header.js +0 -3
- package/dist/interfaces/single-encrypted-parsed-header.js.map +0 -1
- package/dist/interfaces/wallet-seed.d.ts.map +0 -1
- package/dist/interfaces/wallet-seed.js +0 -3
- package/dist/interfaces/wallet-seed.js.map +0 -1
- package/dist/interfaces/wrapped-key-consts.d.ts +0 -7
- package/dist/interfaces/wrapped-key-consts.d.ts.map +0 -1
- package/dist/interfaces/wrapped-key-consts.js +0 -3
- package/dist/interfaces/wrapped-key-consts.js.map +0 -1
- package/dist/member.d.ts +0 -74
- package/dist/member.d.ts.map +0 -1
- package/dist/member.js +0 -273
- package/dist/member.js.map +0 -1
- package/dist/services/aes-gcm.d.ts +0 -66
- package/dist/services/aes-gcm.d.ts.map +0 -1
- package/dist/services/aes-gcm.js +0 -115
- package/dist/services/aes-gcm.js.map +0 -1
- package/dist/services/ecies/crypto-core.d.ts +0 -83
- package/dist/services/ecies/crypto-core.d.ts.map +0 -1
- package/dist/services/ecies/crypto-core.js +0 -166
- package/dist/services/ecies/crypto-core.js.map +0 -1
- package/dist/services/ecies/file.d.ts +0 -30
- package/dist/services/ecies/file.d.ts.map +0 -1
- package/dist/services/ecies/file.js +0 -144
- package/dist/services/ecies/file.js.map +0 -1
- package/dist/services/ecies/index.d.ts.map +0 -1
- package/dist/services/ecies/index.js +0 -24
- package/dist/services/ecies/index.js.map +0 -1
- package/dist/services/ecies/multi-recipient.d.ts +0 -83
- package/dist/services/ecies/multi-recipient.d.ts.map +0 -1
- package/dist/services/ecies/multi-recipient.js +0 -360
- package/dist/services/ecies/multi-recipient.js.map +0 -1
- package/dist/services/ecies/service.d.ts +0 -71
- package/dist/services/ecies/service.d.ts.map +0 -1
- package/dist/services/ecies/service.js +0 -167
- package/dist/services/ecies/service.js.map +0 -1
- package/dist/services/ecies/signature.d.ts +0 -38
- package/dist/services/ecies/signature.d.ts.map +0 -1
- package/dist/services/ecies/signature.js +0 -69
- package/dist/services/ecies/signature.js.map +0 -1
- package/dist/services/ecies/single-recipient.d.ts +0 -86
- package/dist/services/ecies/single-recipient.d.ts.map +0 -1
- package/dist/services/ecies/single-recipient.js +0 -399
- package/dist/services/ecies/single-recipient.js.map +0 -1
- package/dist/services/ecies/utilities.d.ts +0 -22
- package/dist/services/ecies/utilities.d.ts.map +0 -1
- package/dist/services/ecies/utilities.js +0 -75
- package/dist/services/ecies/utilities.js.map +0 -1
- package/dist/services/index.d.ts +0 -4
- package/dist/services/index.d.ts.map +0 -1
- package/dist/services/index.js +0 -20
- package/dist/services/index.js.map +0 -1
- package/dist/services/pbkdf2.d.ts +0 -107
- package/dist/services/pbkdf2.d.ts.map +0 -1
- package/dist/services/pbkdf2.js +0 -195
- package/dist/services/pbkdf2.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -3
- package/dist/types.js.map +0 -1
- package/dist/utils.d.ts +0 -11
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -82
- package/dist/utils.js.map +0 -1
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { TranslationEngine } from '@digitaldefiance/i18n-lib';
|
|
2
|
-
import { EciesStringKey } from '@digitaldefiance/ecies-lib';
|
|
3
|
-
import { IPbkdf2Config, IPBkdf2Consts, Pbkdf2ErrorType } from '@digitaldefiance/ecies-lib';
|
|
4
|
-
import { IConstants } from '../interfaces/constants';
|
|
5
|
-
import { Pbkdf2ProfileEnum } from '../enumerations/pbkdf2-profile';
|
|
6
|
-
import { IPbkdf2Result } from '../interfaces/pbkdf2-result';
|
|
7
|
-
import { IECIESConsts } from '../interfaces/ecies-consts';
|
|
8
|
-
/**
|
|
9
|
-
* Custom PBKDF2 error class that works with the plugin i18n system
|
|
10
|
-
*/
|
|
11
|
-
export declare class NodePbkdf2Error extends Error {
|
|
12
|
-
readonly type: Pbkdf2ErrorType;
|
|
13
|
-
constructor(message: string, type: Pbkdf2ErrorType);
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Service for handling PBKDF2 (Password-Based Key Derivation Function 2) operations.
|
|
17
|
-
* This service provides functionality for:
|
|
18
|
-
* - Generating secure key derivation configurations
|
|
19
|
-
* - Deriving cryptographic keys from passwords
|
|
20
|
-
* - Managing salt and iteration parameters
|
|
21
|
-
* - Both synchronous and asynchronous key derivation
|
|
22
|
-
*/
|
|
23
|
-
export declare class Pbkdf2Service {
|
|
24
|
-
protected readonly engine: TranslationEngine<EciesStringKey>;
|
|
25
|
-
protected readonly profiles: Record<string, IPbkdf2Config>;
|
|
26
|
-
protected readonly eciesConsts: IECIESConsts;
|
|
27
|
-
protected readonly pbkdf2Consts: IPBkdf2Consts;
|
|
28
|
-
constructor(engine: TranslationEngine<EciesStringKey>, profiles?: Record<string, IPbkdf2Config>, eciesParams?: IECIESConsts, pbkdf2Params?: IPBkdf2Consts);
|
|
29
|
-
/**
|
|
30
|
-
* Register a new PBKDF2 profile
|
|
31
|
-
* @param profileName The name of the profile
|
|
32
|
-
* @param config The configuration for the profile
|
|
33
|
-
*/
|
|
34
|
-
registerProfile(profileName: string, config: IPbkdf2Config): void;
|
|
35
|
-
/**
|
|
36
|
-
* Get all registered profile names
|
|
37
|
-
* @returns Array of profile names
|
|
38
|
-
*/
|
|
39
|
-
getRegisteredProfiles(): string[];
|
|
40
|
-
/**
|
|
41
|
-
* Check if a profile is registered
|
|
42
|
-
* @param profileName The name of the profile to check
|
|
43
|
-
* @returns True if the profile exists
|
|
44
|
-
*/
|
|
45
|
-
hasProfile(profileName: string): boolean;
|
|
46
|
-
/**
|
|
47
|
-
* Create a Pbkdf2Service instance from IConstants (for backward compatibility)
|
|
48
|
-
* @param constants The constants object
|
|
49
|
-
* @returns A new Pbkdf2Service instance
|
|
50
|
-
*/
|
|
51
|
-
static fromConstants(constants: IConstants): Pbkdf2Service;
|
|
52
|
-
/**
|
|
53
|
-
* Get a predefined configuration profile for common use cases
|
|
54
|
-
* @param profile The name of the profile to use
|
|
55
|
-
* @returns Configuration object for the specified profile
|
|
56
|
-
*/
|
|
57
|
-
getProfileConfig(profile: string): IPbkdf2Config;
|
|
58
|
-
/**
|
|
59
|
-
* Generate an options object for pbkdf2
|
|
60
|
-
* @param iterations Optional number of iterations (defaults to Pbkdf2IterationsPerSecond)
|
|
61
|
-
* @param saltBytes Optional salt size in bytes (defaults to PBKDF2.SALT_BYTES)
|
|
62
|
-
* @param hashBytes Optional hash size in bytes (defaults to ECIES.SYMMETRIC.KEY_SIZE)
|
|
63
|
-
* @param algorithm Optional hash algorithm (defaults to PBKDF2.ALGORITHM)
|
|
64
|
-
* @returns Configuration object for PBKDF2
|
|
65
|
-
*/
|
|
66
|
-
getConfig(iterations?: number, saltBytes?: number, hashBytes?: number, algorithm?: string): IPbkdf2Config;
|
|
67
|
-
/**
|
|
68
|
-
* Given a password, use pbkdf2 to generate an appropriately sized key for AES encryption
|
|
69
|
-
* @param password The password to derive a key from
|
|
70
|
-
* @param salt Optional salt (will be randomly generated if not provided)
|
|
71
|
-
* @param iterations Optional number of iterations
|
|
72
|
-
* @param saltBytes Optional salt size in bytes
|
|
73
|
-
* @param keySize Optional key size in bytes
|
|
74
|
-
* @param algorithm Optional hash algorithm
|
|
75
|
-
* @returns Object containing the derived key, salt, and iteration count
|
|
76
|
-
*/
|
|
77
|
-
deriveKeyFromPassword(password: Buffer, salt?: Buffer, iterations?: number, saltBytes?: number, keySize?: number, algorithm?: string): IPbkdf2Result;
|
|
78
|
-
/**
|
|
79
|
-
* Async version of deriveKeyFromPassword that uses libuv threadpool via crypto.pbkdf2
|
|
80
|
-
* to avoid blocking the event loop during password verification.
|
|
81
|
-
* @param password The password to derive a key from
|
|
82
|
-
* @param salt Optional salt (will be randomly generated if not provided)
|
|
83
|
-
* @param iterations Optional number of iterations
|
|
84
|
-
* @param saltBytes Optional salt size in bytes
|
|
85
|
-
* @param keySize Optional key size in bytes
|
|
86
|
-
* @param algorithm Optional hash algorithm
|
|
87
|
-
* @returns Promise resolving to object containing the derived key, salt, and iteration count
|
|
88
|
-
*/
|
|
89
|
-
deriveKeyFromPasswordAsync(password: Buffer, salt?: Buffer, iterations?: number, saltBytes?: number, keySize?: number, algorithm?: string): Promise<IPbkdf2Result>;
|
|
90
|
-
/**
|
|
91
|
-
* Derive a key using a predefined configuration profile
|
|
92
|
-
* @param password The password to derive a key from
|
|
93
|
-
* @param profile The configuration profile to use
|
|
94
|
-
* @param salt Optional salt (will be randomly generated if not provided)
|
|
95
|
-
* @returns Object containing the derived key, salt, and iteration count
|
|
96
|
-
*/
|
|
97
|
-
deriveKeyFromPasswordWithProfile(password: Buffer, profile: Pbkdf2ProfileEnum, salt?: Buffer): IPbkdf2Result;
|
|
98
|
-
/**
|
|
99
|
-
* Async version of deriveKeyFromPasswordWithProfile
|
|
100
|
-
* @param password The password to derive a key from
|
|
101
|
-
* @param profile The configuration profile to use
|
|
102
|
-
* @param salt Optional salt (will be randomly generated if not provided)
|
|
103
|
-
* @returns Promise resolving to object containing the derived key, salt, and iteration count
|
|
104
|
-
*/
|
|
105
|
-
deriveKeyFromPasswordWithProfileAsync(password: Buffer, profile: Pbkdf2ProfileEnum, salt?: Buffer): Promise<IPbkdf2Result>;
|
|
106
|
-
}
|
|
107
|
-
//# sourceMappingURL=pbkdf2.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pbkdf2.d.ts","sourceRoot":"","sources":["../../src/services/pbkdf2.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EACL,a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CAAC,EAAE,MAAM,EACnB,SAAS,CAAC,EAAE,MAAM,EAClB,SAAS,CAAC,EAAE,MAAM,EAClB,SAAS,CAAC,EAAE,MAAM,GACjB,aAAa;IAkBhB;;;;;;;;;OASG;IACI,qBAAqB,CAC1B,QAAQ,EAAE,MAAM,EAChB,IAAI,CAAC,EAAE,MAAM,EACb,UAAU,CAAC,EAAE,MAAM,EACnB,SAAS,CAAC,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,MAAM,EAChB,SAAS,CAAC,EAAE,MAAM,GACjB,aAAa;IAsChB;;;;;;;;;;OAUG;IACU,0BAA0B,CACrC,QAAQ,EAAE,MAAM,EAChB,IAAI,CAAC,EAAE,MAAM,EACb,UAAU,CAAC,EAAE,MAAM,EACnB,SAAS,CAAC,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,MAAM,EAChB,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,aAAa,CAAC;IAuCzB;;;;;;OAMG;IACI,gCAAgC,CACrC,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,iBAAiB,EAC1B,IAAI,CAAC,EAAE,MAAM,GACZ,aAAa;IAYhB;;;;;;OAMG;IACU,qCAAqC,CAChD,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,iBAAiB,EAC1B,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,aAAa,CAAC;CAW1B"}
|
package/dist/services/pbkdf2.js
DELETED
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Pbkdf2Service = exports.NodePbkdf2Error = void 0;
|
|
4
|
-
const ecies_lib_1 = require("@digitaldefiance/ecies-lib");
|
|
5
|
-
const crypto_1 = require("crypto");
|
|
6
|
-
const util_1 = require("util");
|
|
7
|
-
const ecies_i18n_factory_1 = require("../i18n/ecies-i18n-factory");
|
|
8
|
-
const constants_1 = require("../constants");
|
|
9
|
-
/**
|
|
10
|
-
* Custom PBKDF2 error class that works with the plugin i18n system
|
|
11
|
-
*/
|
|
12
|
-
class NodePbkdf2Error extends Error {
|
|
13
|
-
type;
|
|
14
|
-
constructor(message, type) {
|
|
15
|
-
super(message);
|
|
16
|
-
this.type = type;
|
|
17
|
-
this.name = 'NodePbkdf2Error';
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
exports.NodePbkdf2Error = NodePbkdf2Error;
|
|
21
|
-
/**
|
|
22
|
-
* Service for handling PBKDF2 (Password-Based Key Derivation Function 2) operations.
|
|
23
|
-
* This service provides functionality for:
|
|
24
|
-
* - Generating secure key derivation configurations
|
|
25
|
-
* - Deriving cryptographic keys from passwords
|
|
26
|
-
* - Managing salt and iteration parameters
|
|
27
|
-
* - Both synchronous and asynchronous key derivation
|
|
28
|
-
*/
|
|
29
|
-
class Pbkdf2Service {
|
|
30
|
-
engine;
|
|
31
|
-
profiles;
|
|
32
|
-
eciesConsts;
|
|
33
|
-
pbkdf2Consts;
|
|
34
|
-
constructor(engine, profiles, eciesParams = constants_1.Constants.ECIES, pbkdf2Params = constants_1.Constants.PBKDF2) {
|
|
35
|
-
this.engine = engine;
|
|
36
|
-
this.profiles = profiles ? { ...profiles } : {};
|
|
37
|
-
const runtimeDefaults = (0, constants_1.getNodeRuntimeConfiguration)();
|
|
38
|
-
this.eciesConsts = eciesParams ?? runtimeDefaults.ECIES;
|
|
39
|
-
this.pbkdf2Consts =
|
|
40
|
-
pbkdf2Params ?? runtimeDefaults.PBKDF2;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Register a new PBKDF2 profile
|
|
44
|
-
* @param profileName The name of the profile
|
|
45
|
-
* @param config The configuration for the profile
|
|
46
|
-
*/
|
|
47
|
-
registerProfile(profileName, config) {
|
|
48
|
-
this.profiles[profileName] = { ...config };
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Get all registered profile names
|
|
52
|
-
* @returns Array of profile names
|
|
53
|
-
*/
|
|
54
|
-
getRegisteredProfiles() {
|
|
55
|
-
return Object.keys(this.profiles);
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Check if a profile is registered
|
|
59
|
-
* @param profileName The name of the profile to check
|
|
60
|
-
* @returns True if the profile exists
|
|
61
|
-
*/
|
|
62
|
-
hasProfile(profileName) {
|
|
63
|
-
return profileName in this.profiles;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Create a Pbkdf2Service instance from IConstants (for backward compatibility)
|
|
67
|
-
* @param constants The constants object
|
|
68
|
-
* @returns A new Pbkdf2Service instance
|
|
69
|
-
*/
|
|
70
|
-
static fromConstants(constants) {
|
|
71
|
-
const engine = (0, ecies_i18n_factory_1.createEciesTranslationEngine)();
|
|
72
|
-
const runtimeDefaults = (0, constants_1.getNodeRuntimeConfiguration)();
|
|
73
|
-
return new Pbkdf2Service(engine, constants.PBKDF2_PROFILES, runtimeDefaults.ECIES, constants.PBKDF2);
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Get a predefined configuration profile for common use cases
|
|
77
|
-
* @param profile The name of the profile to use
|
|
78
|
-
* @returns Configuration object for the specified profile
|
|
79
|
-
*/
|
|
80
|
-
getProfileConfig(profile) {
|
|
81
|
-
const profileConfig = this.profiles[profile];
|
|
82
|
-
if (!profileConfig) {
|
|
83
|
-
throw new NodePbkdf2Error((0, ecies_i18n_factory_1.getNodeEciesTranslation)(ecies_i18n_factory_1.NodeEciesStringKey.Error_Pbkdf2_InvalidSaltLength), ecies_lib_1.Pbkdf2ErrorType.InvalidProfile);
|
|
84
|
-
}
|
|
85
|
-
return {
|
|
86
|
-
hashBytes: profileConfig.hashBytes,
|
|
87
|
-
saltBytes: profileConfig.saltBytes,
|
|
88
|
-
iterations: profileConfig.iterations,
|
|
89
|
-
algorithm: profileConfig.algorithm,
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Generate an options object for pbkdf2
|
|
94
|
-
* @param iterations Optional number of iterations (defaults to Pbkdf2IterationsPerSecond)
|
|
95
|
-
* @param saltBytes Optional salt size in bytes (defaults to PBKDF2.SALT_BYTES)
|
|
96
|
-
* @param hashBytes Optional hash size in bytes (defaults to ECIES.SYMMETRIC.KEY_SIZE)
|
|
97
|
-
* @param algorithm Optional hash algorithm (defaults to PBKDF2.ALGORITHM)
|
|
98
|
-
* @returns Configuration object for PBKDF2
|
|
99
|
-
*/
|
|
100
|
-
getConfig(iterations, saltBytes, hashBytes, algorithm) {
|
|
101
|
-
// larger numbers mean better security, less
|
|
102
|
-
return {
|
|
103
|
-
// size of the generated hash
|
|
104
|
-
hashBytes: hashBytes ?? this.eciesConsts.SYMMETRIC.KEY_SIZE,
|
|
105
|
-
// larger salt means hashed passwords are more resistant to rainbow table, but
|
|
106
|
-
// you get diminishing returns pretty fast
|
|
107
|
-
saltBytes: saltBytes ?? this.pbkdf2Consts.SALT_BYTES,
|
|
108
|
-
// more iterations means an attacker has to take longer to brute force an
|
|
109
|
-
// individual password, so larger is better. however, larger also means longer
|
|
110
|
-
// to hash the password. tune so that hashing the password takes about a
|
|
111
|
-
// second
|
|
112
|
-
iterations: iterations ?? this.pbkdf2Consts.ITERATIONS_PER_SECOND,
|
|
113
|
-
// hash algorithm
|
|
114
|
-
algorithm: algorithm ?? this.pbkdf2Consts.ALGORITHM,
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Given a password, use pbkdf2 to generate an appropriately sized key for AES encryption
|
|
119
|
-
* @param password The password to derive a key from
|
|
120
|
-
* @param salt Optional salt (will be randomly generated if not provided)
|
|
121
|
-
* @param iterations Optional number of iterations
|
|
122
|
-
* @param saltBytes Optional salt size in bytes
|
|
123
|
-
* @param keySize Optional key size in bytes
|
|
124
|
-
* @param algorithm Optional hash algorithm
|
|
125
|
-
* @returns Object containing the derived key, salt, and iteration count
|
|
126
|
-
*/
|
|
127
|
-
deriveKeyFromPassword(password, salt, iterations, saltBytes, keySize, algorithm) {
|
|
128
|
-
const config = this.getConfig(iterations, saltBytes, keySize, algorithm);
|
|
129
|
-
const saltBytes_ = salt ?? (0, crypto_1.randomBytes)(config.saltBytes);
|
|
130
|
-
if (saltBytes_.length !== config.saltBytes) {
|
|
131
|
-
throw new NodePbkdf2Error((0, ecies_i18n_factory_1.getNodeEciesTranslation)(ecies_i18n_factory_1.NodeEciesStringKey.Error_Pbkdf2_InvalidSaltLength), ecies_lib_1.Pbkdf2ErrorType.InvalidSaltLength);
|
|
132
|
-
}
|
|
133
|
-
const hashBytes = (0, crypto_1.pbkdf2Sync)(password, saltBytes_, config.iterations, config.hashBytes, config.algorithm);
|
|
134
|
-
if (hashBytes.length !== config.hashBytes) {
|
|
135
|
-
throw new NodePbkdf2Error((0, ecies_i18n_factory_1.getNodeEciesTranslation)(ecies_i18n_factory_1.NodeEciesStringKey.Error_Pbkdf2_InvalidHashLength), ecies_lib_1.Pbkdf2ErrorType.InvalidHashLength);
|
|
136
|
-
}
|
|
137
|
-
return {
|
|
138
|
-
salt: saltBytes_,
|
|
139
|
-
hash: hashBytes,
|
|
140
|
-
iterations: config.iterations,
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Async version of deriveKeyFromPassword that uses libuv threadpool via crypto.pbkdf2
|
|
145
|
-
* to avoid blocking the event loop during password verification.
|
|
146
|
-
* @param password The password to derive a key from
|
|
147
|
-
* @param salt Optional salt (will be randomly generated if not provided)
|
|
148
|
-
* @param iterations Optional number of iterations
|
|
149
|
-
* @param saltBytes Optional salt size in bytes
|
|
150
|
-
* @param keySize Optional key size in bytes
|
|
151
|
-
* @param algorithm Optional hash algorithm
|
|
152
|
-
* @returns Promise resolving to object containing the derived key, salt, and iteration count
|
|
153
|
-
*/
|
|
154
|
-
async deriveKeyFromPasswordAsync(password, salt, iterations, saltBytes, keySize, algorithm) {
|
|
155
|
-
const config = this.getConfig(iterations, saltBytes, keySize, algorithm);
|
|
156
|
-
const saltBytes_ = salt ?? (0, crypto_1.randomBytes)(config.saltBytes);
|
|
157
|
-
if (saltBytes_.length !== config.saltBytes) {
|
|
158
|
-
throw new NodePbkdf2Error((0, ecies_i18n_factory_1.getNodeEciesTranslation)(ecies_i18n_factory_1.NodeEciesStringKey.Error_Pbkdf2_InvalidSaltLength), ecies_lib_1.Pbkdf2ErrorType.InvalidSaltLength);
|
|
159
|
-
}
|
|
160
|
-
const pbkdf2 = (0, util_1.promisify)(crypto_1.pbkdf2);
|
|
161
|
-
const hashBytes = (await pbkdf2(password, saltBytes_, config.iterations, config.hashBytes, config.algorithm));
|
|
162
|
-
if (hashBytes.length !== config.hashBytes) {
|
|
163
|
-
throw new NodePbkdf2Error((0, ecies_i18n_factory_1.getNodeEciesTranslation)(ecies_i18n_factory_1.NodeEciesStringKey.Error_Pbkdf2_InvalidHashLength), ecies_lib_1.Pbkdf2ErrorType.InvalidHashLength);
|
|
164
|
-
}
|
|
165
|
-
return {
|
|
166
|
-
salt: saltBytes_,
|
|
167
|
-
hash: hashBytes,
|
|
168
|
-
iterations: config.iterations,
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Derive a key using a predefined configuration profile
|
|
173
|
-
* @param password The password to derive a key from
|
|
174
|
-
* @param profile The configuration profile to use
|
|
175
|
-
* @param salt Optional salt (will be randomly generated if not provided)
|
|
176
|
-
* @returns Object containing the derived key, salt, and iteration count
|
|
177
|
-
*/
|
|
178
|
-
deriveKeyFromPasswordWithProfile(password, profile, salt) {
|
|
179
|
-
const config = this.getProfileConfig(profile);
|
|
180
|
-
return this.deriveKeyFromPassword(password, salt, config.iterations, config.saltBytes, config.hashBytes, config.algorithm);
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Async version of deriveKeyFromPasswordWithProfile
|
|
184
|
-
* @param password The password to derive a key from
|
|
185
|
-
* @param profile The configuration profile to use
|
|
186
|
-
* @param salt Optional salt (will be randomly generated if not provided)
|
|
187
|
-
* @returns Promise resolving to object containing the derived key, salt, and iteration count
|
|
188
|
-
*/
|
|
189
|
-
async deriveKeyFromPasswordWithProfileAsync(password, profile, salt) {
|
|
190
|
-
const config = this.getProfileConfig(profile);
|
|
191
|
-
return this.deriveKeyFromPasswordAsync(password, salt, config.iterations, config.saltBytes, config.hashBytes, config.algorithm);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
exports.Pbkdf2Service = Pbkdf2Service;
|
|
195
|
-
//# sourceMappingURL=pbkdf2.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pbkdf2.js","sourceRoot":"","sources":["../../src/services/pbkdf2.ts"],"names":[],"mappings":";;;AAEA,0DAIoC;AACpC,mCAAwE;AACxE,+BAAiC;AAGjC,mEAAuH;AAGvH,4CAAsE;AAEtE;;GAEG;AACH,MAAa,eAAgB,SAAQ,KAAK;IACK;IAA7C,YAAY,OAAe,EAAkB,IAAqB;QAChE,KAAK,CAAC,OAAO,CAAC,CAAC;QAD4B,SAAI,GAAJ,IAAI,CAAiB;QAEhE,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AALD,0CAKC;AAED;;;;;;;GAOG;AACH,MAAa,aAAa;IACL,MAAM,CAAoC;IAC1C,QAAQ,CAAgC;IACxC,WAAW,CAAe;IAC1B,YAAY,CAAgB;IAE/C,YACE,MAAyC,EACzC,QAAwC,EACxC,cAA4B,qBAAS,CAAC,KAAK,EAC3C,eAA8B,qBAAS,CAAC,MAAM;QAE9C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC,CAAC,CAAC,EAAE,GAAG,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAChD,MAAM,eAAe,GAAG,IAAA,uCAA2B,GAAE,CAAC;QACtD,IAAI,CAAC,WAAW,GAAG,WAAW,IAAI,eAAe,CAAC,KAAK,CAAC;QACxD,IAAI,CAAC,YAAY;YAC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AyB,EACzB,0BAA0B,CAC3B,CAAC;AACF,MAAM,MAAM,aAAa,GAAG,KAAK,CAAC,mBAAmB,EAAE,eAAe,CAAC,CAAC;AACxE,MAAM,MAAM,mBAAmB,GAAG,KAAK,CACrC,oBAAoB,EACpB,qBAAqB,CACtB,CAAC;AACF,MAAM,MAAM,mBAAmB,GAAG,KAAK,CACrC,oBAAoB,EACpB,qBAAqB,CACtB,CAAC;AACF,MAAM,MAAM,yBAAyB,GAAG,KAAK,CAC3C,0BAA0B,EAC1B,2BAA2B,CAC5B,CAAC;AACF,MAAM,MAAM,eAAe,GAAG,KAAK,CAAC,SAAS,EAAE,iBAAiB,CAAC,CAAC;AAClE,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,KAAK,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;AACxE,MAAM,MAAM,cAAc,GAAG,MAAM,GACjC,KAAK,CAAC,MAAM,EAAE,cAAc,EAAE,gBAAgB,CAAC,CAAC;AAClD,MAAM,MAAM,cAAc,GAAG,KAAK,CAAC,SAAS,EAAE,cAAc,EAAE,gBAAgB,CAAC,CAAC;AAEhF;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG;IAChC,QAAQ,IAAI,MAAM,CAAC;IACnB,KAAK,IAAI,MAAM,CAAC;CACjB,CAAC"}
|
package/dist/types.js
DELETED
package/dist/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/dist/utils.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Encodes the length of the data in the buffer
|
|
3
|
-
* @param buffer The buffer to encode
|
|
4
|
-
* @returns The encoded buffer
|
|
5
|
-
*/
|
|
6
|
-
export declare function lengthEncodeData(buffer: Buffer): Buffer;
|
|
7
|
-
export declare function decodeLengthEncodedData(buffer: Buffer): {
|
|
8
|
-
data: Buffer;
|
|
9
|
-
totalLength: number;
|
|
10
|
-
};
|
|
11
|
-
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAuBA;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAuBvD;AAED,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG;IACvD,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;CACrB,CA+CA"}
|
package/dist/utils.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.lengthEncodeData = lengthEncodeData;
|
|
4
|
-
exports.decodeLengthEncodedData = decodeLengthEncodedData;
|
|
5
|
-
const ecies_lib_1 = require("@digitaldefiance/ecies-lib");
|
|
6
|
-
const ecies_i18n_factory_1 = require("./i18n/ecies-i18n-factory");
|
|
7
|
-
/**
|
|
8
|
-
* Custom error class for length encoding errors
|
|
9
|
-
*/
|
|
10
|
-
class LengthEncodingError extends Error {
|
|
11
|
-
constructor(message) {
|
|
12
|
-
super(message);
|
|
13
|
-
this.name = 'LengthEncodingError';
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Encodes the length of the data in the buffer
|
|
18
|
-
* @param buffer The buffer to encode
|
|
19
|
-
* @returns The encoded buffer
|
|
20
|
-
*/
|
|
21
|
-
function lengthEncodeData(buffer) {
|
|
22
|
-
const lengthType = (0, ecies_lib_1.getLengthEncodingTypeForLength)(buffer.length);
|
|
23
|
-
const lengthTypeSize = (0, ecies_lib_1.getLengthForLengthType)(lengthType);
|
|
24
|
-
const result = Buffer.alloc(1 + lengthTypeSize + buffer.length);
|
|
25
|
-
result.writeUInt8(lengthType, 0);
|
|
26
|
-
switch (lengthType) {
|
|
27
|
-
case ecies_lib_1.LengthEncodingType.UInt8:
|
|
28
|
-
result.writeUInt8(buffer.length, 1);
|
|
29
|
-
break;
|
|
30
|
-
case ecies_lib_1.LengthEncodingType.UInt16:
|
|
31
|
-
result.writeUInt16BE(buffer.length, 1);
|
|
32
|
-
break;
|
|
33
|
-
case ecies_lib_1.LengthEncodingType.UInt32:
|
|
34
|
-
result.writeUInt32BE(buffer.length, 1);
|
|
35
|
-
break;
|
|
36
|
-
case ecies_lib_1.LengthEncodingType.UInt64:
|
|
37
|
-
result.writeBigUInt64BE(BigInt(buffer.length), 1);
|
|
38
|
-
break;
|
|
39
|
-
}
|
|
40
|
-
buffer.copy(result, 1 + lengthTypeSize);
|
|
41
|
-
return result;
|
|
42
|
-
}
|
|
43
|
-
function decodeLengthEncodedData(buffer) {
|
|
44
|
-
const pluginEngine = (0, ecies_i18n_factory_1.getEciesPluginI18nEngine)();
|
|
45
|
-
if (buffer.length < 1) {
|
|
46
|
-
throw new RangeError(pluginEngine.translate(ecies_i18n_factory_1.NodeEciesComponentId, ecies_i18n_factory_1.NodeEciesStringKey.Error_BufferIsTooShort));
|
|
47
|
-
}
|
|
48
|
-
const lengthType = (0, ecies_lib_1.getLengthEncodingTypeFromValue)(buffer.readUint8(0));
|
|
49
|
-
const lengthTypeSize = (0, ecies_lib_1.getLengthForLengthType)(lengthType);
|
|
50
|
-
if (buffer.length < 1 + lengthTypeSize) {
|
|
51
|
-
throw new RangeError(pluginEngine.translate(ecies_i18n_factory_1.NodeEciesComponentId, ecies_i18n_factory_1.NodeEciesStringKey.Error_BufferIsTooShortToReadFullLengthValue));
|
|
52
|
-
}
|
|
53
|
-
let length;
|
|
54
|
-
switch (lengthType) {
|
|
55
|
-
case ecies_lib_1.LengthEncodingType.UInt8:
|
|
56
|
-
length = buffer.readUint8(1);
|
|
57
|
-
break;
|
|
58
|
-
case ecies_lib_1.LengthEncodingType.UInt16:
|
|
59
|
-
length = buffer.readUint16BE(1);
|
|
60
|
-
break;
|
|
61
|
-
case ecies_lib_1.LengthEncodingType.UInt32:
|
|
62
|
-
length = buffer.readUint32BE(1);
|
|
63
|
-
break;
|
|
64
|
-
case ecies_lib_1.LengthEncodingType.UInt64:
|
|
65
|
-
length = buffer.readBigUInt64BE(1);
|
|
66
|
-
if (Number(length) > Number.MAX_SAFE_INTEGER) {
|
|
67
|
-
throw new RangeError(pluginEngine.translate(ecies_i18n_factory_1.NodeEciesComponentId, ecies_i18n_factory_1.NodeEciesStringKey.Error_LengthExceedsMaximumSafeInteger));
|
|
68
|
-
}
|
|
69
|
-
break;
|
|
70
|
-
default:
|
|
71
|
-
throw new LengthEncodingError((0, ecies_i18n_factory_1.getNodeEciesTranslation)(ecies_i18n_factory_1.NodeEciesStringKey.Error_LengthError_LengthIsInvalidType));
|
|
72
|
-
}
|
|
73
|
-
const totalLength = 1 + lengthTypeSize + Number(length);
|
|
74
|
-
if (totalLength > buffer.length) {
|
|
75
|
-
throw new RangeError(pluginEngine.translate(ecies_i18n_factory_1.NodeEciesComponentId, ecies_i18n_factory_1.NodeEciesStringKey.Error_BufferIsTooShortForDeclaredDataLength));
|
|
76
|
-
}
|
|
77
|
-
return {
|
|
78
|
-
data: buffer.subarray(1 + lengthTypeSize, totalLength),
|
|
79
|
-
totalLength,
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
//# sourceMappingURL=utils.js.map
|
package/dist/utils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;AA4BA,4CAuBC;AAED,0DAkDC;AAvGD,0DAKoC;AACpC,kEAKmC;AAEnC;;GAEG;AACH,MAAM,mBAAoB,SAAQ,KAAK;IACrC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF;AAED;;;;G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