@shellicar/core-config 2.0.0 → 2.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 +1 -1
- package/dist/cjs/EncryptedValue.cjs +1 -0
- package/dist/cjs/EncryptedValue.cjs.map +1 -0
- package/dist/cjs/EncryptedValue.d.cts +12 -0
- package/dist/cjs/SecureConnectionString.cjs +1 -0
- package/dist/cjs/SecureConnectionString.cjs.map +1 -0
- package/dist/cjs/SecureConnectionString.d.cts +17 -0
- package/dist/cjs/SecureString.cjs +1 -0
- package/dist/cjs/SecureString.cjs.map +1 -0
- package/dist/cjs/SecureString.d.cts +16 -0
- package/dist/cjs/SecureURL.cjs +1 -0
- package/dist/cjs/SecureURL.cjs.map +1 -0
- package/dist/cjs/SecureURL.d.cts +21 -0
- package/dist/cjs/chunk-7PP3CDDK.cjs +1 -0
- package/dist/cjs/chunk-7PP3CDDK.cjs.map +1 -0
- package/dist/cjs/chunk-FKX4J4Q2.cjs +1 -0
- package/dist/cjs/chunk-FKX4J4Q2.cjs.map +1 -0
- package/dist/cjs/chunk-J7CRMQ5Z.cjs +1 -0
- package/dist/cjs/chunk-J7CRMQ5Z.cjs.map +1 -0
- package/dist/cjs/chunk-JS7CWWUD.cjs +1 -0
- package/dist/cjs/chunk-JS7CWWUD.cjs.map +1 -0
- package/dist/cjs/chunk-JVM3GGW6.cjs +1 -0
- package/dist/cjs/chunk-JVM3GGW6.cjs.map +1 -0
- package/dist/cjs/chunk-PK6SKIKE.cjs +1 -0
- package/dist/cjs/chunk-PK6SKIKE.cjs.map +1 -0
- package/dist/cjs/chunk-VQ2XCAJT.cjs +1 -0
- package/dist/cjs/chunk-VQ2XCAJT.cjs.map +1 -0
- package/dist/cjs/chunk-WZWXGAJN.cjs +1 -0
- package/dist/cjs/chunk-WZWXGAJN.cjs.map +1 -0
- package/dist/cjs/chunk-XVDIOMZD.cjs +1 -0
- package/dist/cjs/chunk-XVDIOMZD.cjs.map +1 -0
- package/dist/cjs/createFactory.cjs +1 -0
- package/dist/cjs/createFactory.cjs.map +1 -0
- package/dist/cjs/createFactory.d.cts +8 -0
- package/dist/cjs/defaults.cjs +1 -0
- package/dist/cjs/defaults.cjs.map +1 -0
- package/dist/cjs/defaults.d.cts +3 -0
- package/dist/cjs/hash.cjs +1 -0
- package/dist/cjs/hash.cjs.map +1 -0
- package/dist/cjs/hash.d.cts +3 -0
- package/dist/cjs/index.cjs +1 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +6 -0
- package/dist/cjs/interfaces.cjs +1 -0
- package/dist/cjs/interfaces.cjs.map +1 -0
- package/dist/cjs/interfaces.d.cts +28 -0
- package/dist/cjs/types.cjs +1 -0
- package/dist/cjs/types.cjs.map +1 -0
- package/dist/cjs/types.d.cts +24 -0
- package/dist/esm/EncryptedValue.d.ts +12 -0
- package/dist/esm/EncryptedValue.js +1 -0
- package/dist/esm/EncryptedValue.js.map +1 -0
- package/dist/esm/SecureConnectionString.d.ts +17 -0
- package/dist/esm/SecureConnectionString.js +1 -0
- package/dist/esm/SecureConnectionString.js.map +1 -0
- package/dist/esm/SecureString.d.ts +16 -0
- package/dist/esm/SecureString.js +1 -0
- package/dist/esm/SecureString.js.map +1 -0
- package/dist/esm/SecureURL.d.ts +21 -0
- package/dist/esm/SecureURL.js +1 -0
- package/dist/esm/SecureURL.js.map +1 -0
- package/dist/esm/chunk-7QVYU63E.js +1 -0
- package/dist/esm/chunk-7QVYU63E.js.map +1 -0
- package/dist/esm/chunk-CGPJ25IS.js +1 -0
- package/dist/esm/chunk-CGPJ25IS.js.map +1 -0
- package/dist/esm/chunk-FUGQ3OFQ.js +1 -0
- package/dist/esm/chunk-FUGQ3OFQ.js.map +1 -0
- package/dist/esm/chunk-GJXVQ2LL.js +1 -0
- package/dist/esm/chunk-GJXVQ2LL.js.map +1 -0
- package/dist/esm/chunk-JAXX5FG7.js +1 -0
- package/dist/esm/chunk-JAXX5FG7.js.map +1 -0
- package/dist/esm/chunk-NWPDBO55.js +1 -0
- package/dist/esm/chunk-NWPDBO55.js.map +1 -0
- package/dist/esm/chunk-S3UXVGVK.js +1 -0
- package/dist/esm/chunk-S3UXVGVK.js.map +1 -0
- package/dist/esm/chunk-TGJY6ZQ7.js +1 -0
- package/dist/esm/chunk-TGJY6ZQ7.js.map +1 -0
- package/dist/esm/chunk-XICVVAG4.js +1 -0
- package/dist/esm/chunk-XICVVAG4.js.map +1 -0
- package/dist/esm/createFactory.d.ts +8 -0
- package/dist/esm/createFactory.js +1 -0
- package/dist/esm/createFactory.js.map +1 -0
- package/dist/esm/defaults.d.ts +3 -0
- package/dist/esm/defaults.js +1 -0
- package/dist/esm/defaults.js.map +1 -0
- package/dist/esm/hash.d.ts +3 -0
- package/dist/esm/hash.js +1 -0
- package/dist/esm/hash.js.map +1 -0
- package/dist/esm/index.d.ts +6 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/interfaces.d.ts +28 -0
- package/dist/esm/interfaces.js +1 -0
- package/dist/esm/interfaces.js.map +1 -0
- package/dist/esm/types.d.ts +24 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/types.js.map +1 -0
- package/package.json +21 -15
- package/dist/index.cjs +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -63
- package/dist/index.d.ts +0 -63
- package/dist/index.js +0 -1
- package/dist/index.js.map +0 -1
package/LICENSE
CHANGED
|
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("./chunk-FKX4J4Q2.cjs");require("./chunk-PK6SKIKE.cjs"),Object.defineProperty(exports,"EncryptedValue",{enumerable:!0,get:function(){return e.EncryptedValue}});//# sourceMappingURL=EncryptedValue.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"EncryptedValue.cjs"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare class EncryptedValue {
|
|
2
|
+
private readonly encryptedData;
|
|
3
|
+
private readonly iv;
|
|
4
|
+
private readonly authTag;
|
|
5
|
+
private readonly key;
|
|
6
|
+
constructor(value: string);
|
|
7
|
+
getValue(): string;
|
|
8
|
+
toString(): string;
|
|
9
|
+
toJSON(): object;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { EncryptedValue };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("./chunk-J7CRMQ5Z.cjs");require("./chunk-XVDIOMZD.cjs"),require("./chunk-JVM3GGW6.cjs"),require("./chunk-WZWXGAJN.cjs"),require("./chunk-PK6SKIKE.cjs"),Object.defineProperty(exports,"SecureConnectionString",{enumerable:!0,get:function(){return e.SecureConnectionString}});//# sourceMappingURL=SecureConnectionString.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"SecureConnectionString.cjs"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import util, { InspectOptions } from 'node:util';
|
|
2
|
+
import { ISecureConnectionString } from './interfaces.cjs';
|
|
3
|
+
import { SecureConfig, InspectFunction } from './types.cjs';
|
|
4
|
+
|
|
5
|
+
declare class SecureConnectionString extends ISecureConnectionString {
|
|
6
|
+
#private;
|
|
7
|
+
get secretValue(): string;
|
|
8
|
+
private constructor();
|
|
9
|
+
private parseConnectionString;
|
|
10
|
+
static factory(config: SecureConfig): (value: string) => SecureConnectionString;
|
|
11
|
+
static from<T extends string | null | undefined>(value: T, config: SecureConfig): T extends string ? SecureConnectionString : T;
|
|
12
|
+
toString(): string;
|
|
13
|
+
toJSON(): object;
|
|
14
|
+
[util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { SecureConnectionString };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("./chunk-XVDIOMZD.cjs");require("./chunk-JVM3GGW6.cjs"),require("./chunk-WZWXGAJN.cjs"),require("./chunk-PK6SKIKE.cjs"),Object.defineProperty(exports,"SecureString",{enumerable:!0,get:function(){return e.SecureString}});//# sourceMappingURL=SecureString.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"SecureString.cjs"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import util, { InspectOptions } from 'node:util';
|
|
2
|
+
import { ISecureString } from './interfaces.cjs';
|
|
3
|
+
import { SecureConfig, InspectFunction } from './types.cjs';
|
|
4
|
+
|
|
5
|
+
declare class SecureString extends ISecureString {
|
|
6
|
+
#private;
|
|
7
|
+
get secretValue(): string;
|
|
8
|
+
private constructor();
|
|
9
|
+
static factory(config: SecureConfig): (value: string) => SecureString;
|
|
10
|
+
static from<T extends string | null | undefined>(value: T, config: SecureConfig): T extends string ? SecureString : T;
|
|
11
|
+
toString(): string;
|
|
12
|
+
toJSON(): string;
|
|
13
|
+
[util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { SecureString };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("./chunk-VQ2XCAJT.cjs");require("./chunk-XVDIOMZD.cjs"),require("./chunk-JVM3GGW6.cjs"),require("./chunk-WZWXGAJN.cjs"),require("./chunk-PK6SKIKE.cjs"),Object.defineProperty(exports,"SecureURL",{enumerable:!0,get:function(){return e.SecureURL}});//# sourceMappingURL=SecureURL.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"SecureURL.cjs"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import util, { InspectOptions } from 'node:util';
|
|
2
|
+
import { ISecureURL } from './interfaces.cjs';
|
|
3
|
+
import { SecureConfig, InspectFunction } from './types.cjs';
|
|
4
|
+
|
|
5
|
+
type UrlObject = {
|
|
6
|
+
href: string;
|
|
7
|
+
password?: string;
|
|
8
|
+
searchParams?: Record<string, string>;
|
|
9
|
+
};
|
|
10
|
+
declare class SecureURL extends ISecureURL {
|
|
11
|
+
#private;
|
|
12
|
+
get secretValue(): URL;
|
|
13
|
+
private constructor();
|
|
14
|
+
static factory(config: SecureConfig): (value: URL) => ISecureURL;
|
|
15
|
+
static from<T extends URL | null | undefined>(value: T, config: SecureConfig): T extends URL ? SecureURL : T;
|
|
16
|
+
toString(): string;
|
|
17
|
+
toJSON(): UrlObject;
|
|
18
|
+
[util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { SecureURL };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("./chunk-FKX4J4Q2.cjs"),r=require("./chunk-J7CRMQ5Z.cjs"),c=require("./chunk-VQ2XCAJT.cjs"),n=require("./chunk-XVDIOMZD.cjs"),t=require("./chunk-JS7CWWUD.cjs"),u=require("./chunk-PK6SKIKE.cjs"),i={encrypt:u.__name(r=>new e.EncryptedValue(r),"encrypt")},s=u.__name(e=>{const u={secret:e?.secret??null,encryptionProvider:e?.encryptionProvider??i,secretKeys:e?.secretKeys??t.defaultSecureKeys};return{string:n.SecureString.factory(u),connectionString:r.SecureConnectionString.factory(u),url:c.SecureURL.factory(u)}},"createFactory");exports.createFactory=s,exports.defaultEncryptionProvider=i;//# sourceMappingURL=chunk-7PP3CDDK.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/createFactory.ts"],"names":["__name","EncryptedValue","defaultSecureKeys","SecureString","SecureConnectionString","SecureURL"],"mappings":";AAQO,IAAM,yBAAA,GAAiD;AAAA,EAC5D,yBAASA,wBAAA,CAAA,CAAC,KAAA,KAAkB,IAAIC,gCAAA,CAAe,KAAK,CAAA,EAA3C,SAAA;AACX;AAEO,IAAM,aAAA,6CAAiB,OAAA,KAAoD;AAChF,EAAA,MAAM,MAAA,GAAuB;AAAA,IAC3B,MAAA,EAAQ,SAAS,MAAA,IAAU,IAAA;AAAA,IAC3B,kBAAA,EAAoB,SAAS,kBAAA,IAAsB,yBAAA;AAAA,IACnD,UAAA,EAAY,SAAS,UAAA,IAAcC;AAAA,GACrC;AAEA,EAAA,OAAO;AAAA,IACL,MAAA,EAAQC,8BAAA,CAAa,OAAA,CAAQ,MAAM,CAAA;AAAA,IACnC,gBAAA,EAAkBC,wCAAA,CAAuB,OAAA,CAAQ,MAAM,CAAA;AAAA,IACvD,GAAA,EAAKC,2BAAA,CAAU,OAAA,CAAQ,MAAM;AAAA,GAC/B;AACF,CAAA,EAZ6B,eAAA","file":"chunk-7PP3CDDK.cjs","sourcesContent":["import { defaultSecureKeys } from './defaults';\nimport { EncryptedValue } from './EncryptedValue';\nimport type { ISecureFactory } from './interfaces';\nimport { SecureConnectionString } from './SecureConnectionString';\nimport { SecureString } from './SecureString';\nimport { SecureURL } from './SecureURL';\nimport type { IEncryptionProvider, SecureConfig } from './types';\n\nexport const defaultEncryptionProvider: IEncryptionProvider = {\n encrypt: (value: string) => new EncryptedValue(value),\n};\n\nexport const createFactory = (options?: Partial<SecureConfig>): ISecureFactory => {\n const config: SecureConfig = {\n secret: options?.secret ?? null,\n encryptionProvider: options?.encryptionProvider ?? defaultEncryptionProvider,\n secretKeys: options?.secretKeys ?? defaultSecureKeys,\n };\n\n return {\n string: SecureString.factory(config),\n connectionString: SecureConnectionString.factory(config),\n url: SecureURL.factory(config),\n };\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var t=require("./chunk-PK6SKIKE.cjs"),e=require("node:crypto"),r=class{static{t.__name(this,"EncryptedValue")}encryptedData;iv;authTag;key;constructor(t){this.key=e.randomBytes(32),this.iv=e.randomBytes(16);const r=e.createCipheriv("aes-256-gcm",this.key,this.iv),a=[];a.push(r.update(t,"utf8")),a.push(r.final()),this.encryptedData=Buffer.concat(a),this.authTag=r.getAuthTag()}getValue(){const t=e.createDecipheriv("aes-256-gcm",this.key,this.iv);t.setAuthTag(this.authTag);try{const e=[];return e.push(t.update(this.encryptedData)),e.push(t.final()),Buffer.concat(e).toString("utf8")}catch(t){throw new Error("Failed to decrypt value: Invalid key or corrupted data")}}toString(){return"[EncryptedValue]"}toJSON(){return{type:"EncryptedValue",encrypted:!0}}};exports.EncryptedValue=r;//# sourceMappingURL=chunk-FKX4J4Q2.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/EncryptedValue.ts"],"names":["__name","randomBytes","createCipheriv","createDecipheriv"],"mappings":"sGAEO,IAAM,iBAAN,MAAqB;AAAA,EAF5B;AAE4B,IAAAA,wBAAA,CAAA,IAAA,EAAA,gBAAA,CAAA;AAAA;AAAA,EACT,aAAA;AAAA,EACA,EAAA;AAAA,EACA,OAAA;AAAA,EACA,GAAA;AAAA,EAEV,YAAY,KAAA,EAAe;AAChC,IAAA,IAAA,CAAK,GAAA,GAAMC,wBAAY,EAAE,CAAA;AACzB,IAAA,IAAA,CAAK,EAAA,GAAKA,wBAAY,EAAE,CAAA;AAExB,IAAA,MAAM,SAASC,0BAAA,CAAe,aAAA,EAAe,IAAA,CAAK,GAAA,EAAK,KAAK,EAAE,CAAA;AAE9D,IAAA,MAAM,kBAA4B,EAAC;AACnC,IAAA,eAAA,CAAgB,IAAA,CAAK,MAAA,CAAO,MAAA,CAAO,KAAA,EAAO,MAAM,CAAC,CAAA;AACjD,IAAA,eAAA,CAAgB,IAAA,CAAK,MAAA,CAAO,KAAA,EAAO,CAAA;AAEnC,IAAA,IAAA,CAAK,aAAA,GAAgB,MAAA,CAAO,MAAA,CAAO,eAAe,CAAA;AAClD,IAAA,IAAA,CAAK,OAAA,GAAU,OAAO,UAAA,EAAW;AAAA,EACnC;AAAA,EAEO,QAAA,GAAmB;AACxB,IAAA,MAAM,WAAWC,4BAAA,CAAiB,aAAA,EAAe,IAAA,CAAK,GAAA,EAAK,KAAK,EAAE,CAAA;AAClE,IAAA,QAAA,CAAS,UAAA,CAAW,KAAK,OAAO,CAAA;AAEhC,IAAA,IAAI;AACF,MAAA,MAAM,kBAA4B,EAAC;AACnC,MAAA,eAAA,CAAgB,IAAA,CAAK,QAAA,CAAS,MAAA,CAAO,IAAA,CAAK,aAAa,CAAC,CAAA;AACxD,MAAA,eAAA,CAAgB,IAAA,CAAK,QAAA,CAAS,KAAA,EAAO,CAAA;AAErC,MAAA,OAAO,MAAA,CAAO,MAAA,CAAO,eAAe,CAAA,CAAE,SAAS,MAAM,CAAA;AAAA,IACvD,SAAS,CAAA,EAAG;AAEV,MAAA,MAAM,IAAI,MAAM,wDAAwD,CAAA;AAAA,IAC1E;AAAA,EACF;AAAA,EAEO,QAAA,GAAmB;AACxB,IAAA,OAAO,kBAAA;AAAA,EACT;AAAA,EAEO,MAAA,GAAiB;AACtB,IAAA,OAAO,EAAE,IAAA,EAAM,gBAAA,EAAkB,SAAA,EAAW,IAAA,EAAK;AAAA,EACnD;AACF","file":"chunk-FKX4J4Q2.cjs","sourcesContent":["import { createCipheriv, createDecipheriv, randomBytes } from 'node:crypto';\n\nexport class EncryptedValue {\n private readonly encryptedData: Buffer;\n private readonly iv: Buffer;\n private readonly authTag: Buffer;\n private readonly key: Buffer;\n\n public constructor(value: string) {\n this.key = randomBytes(32);\n this.iv = randomBytes(16);\n\n const cipher = createCipheriv('aes-256-gcm', this.key, this.iv);\n\n const encryptedChunks: Buffer[] = [];\n encryptedChunks.push(cipher.update(value, 'utf8'));\n encryptedChunks.push(cipher.final());\n\n this.encryptedData = Buffer.concat(encryptedChunks);\n this.authTag = cipher.getAuthTag();\n }\n\n public getValue(): string {\n const decipher = createDecipheriv('aes-256-gcm', this.key, this.iv);\n decipher.setAuthTag(this.authTag);\n\n try {\n const decryptedChunks: Buffer[] = [];\n decryptedChunks.push(decipher.update(this.encryptedData));\n decryptedChunks.push(decipher.final());\n\n return Buffer.concat(decryptedChunks).toString('utf8');\n } catch (_) {\n // Hide internal error details\n throw new Error('Failed to decrypt value: Invalid key or corrupted data');\n }\n }\n\n public toString(): string {\n return '[EncryptedValue]';\n }\n\n public toJSON(): object {\n return { type: 'EncryptedValue', encrypted: true };\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("./chunk-XVDIOMZD.cjs"),t=require("./chunk-JVM3GGW6.cjs"),r=require("./chunk-PK6SKIKE.cjs");function n(e){return e&&e.__esModule?e:{default:e}}var i=n(require("node:util")),c=class n extends t.ISecureConnectionString{static{r.__name(this,"SecureConnectionString")}#e;#t;get secretValue(){return this.#e.getValue()}constructor(e,t){super(),this.#e=t.encryptionProvider.encrypt(e),this.#t=this.parseConnectionString(e,t.secretKeys.map(e=>e.toLocaleLowerCase()),t)}parseConnectionString(t,r,n){return t.split(";").filter(Boolean).map(t=>{const[i,c]=t.split("="),o=c??"",u=r.includes(i.toLocaleLowerCase())?e.SecureString.from(o,n):o;return[i,u]})}static factory(e){return t=>n.from(t,e)}static from(e,t){return null===e?null:void 0!==e?new n(e,t):void 0}toString(){return this.#t.map(([e,t])=>`${e}=${t}`).join(";")}toJSON(){return Object.fromEntries(this.#t)}[i.default.inspect.custom](e,t,r){if(e<0)return"[SecureConnectionString]";const n=Object.assign({},t,{depth:null==t.depth?null:t.depth-1});return r(this.toJSON(),n)}};exports.SecureConnectionString=c;//# sourceMappingURL=chunk-J7CRMQ5Z.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/SecureConnectionString.ts"],"names":["ISecureConnectionString","__name","value","SecureString","util"],"mappings":"uTAKO,IAAM,sBAAA,GAAN,MAAM,uBAAA,SAA+BA,yCAAA,CAAwB;AAAA,EALpE;AAKoE,IAAAC,wBAAA,CAAA,IAAA,EAAA,wBAAA,CAAA;AAAA;AAAA,EACzD,eAAA;AAAA,EACA,KAAA;AAAA,EAET,IAAW,WAAA,GAAsB;AAC/B,IAAA,OAAO,IAAA,CAAK,gBAAgB,QAAA,EAAS;AAAA,EACvC;AAAA,EAEQ,WAAA,CAAY,OAAe,MAAA,EAAsB;AACvD,IAAA,KAAA,EAAM;AACN,IAAA,IAAA,CAAK,eAAA,GAAkB,MAAA,CAAO,kBAAA,CAAmB,OAAA,CAAQ,KAAK,CAAA;AAC9D,IAAA,IAAA,CAAK,QAAQ,IAAA,CAAK,qBAAA;AAAA,MAChB,KAAA;AAAA,MACA,OAAO,UAAA,CAAW,GAAA,CAAI,CAAC,CAAA,KAAM,CAAA,CAAE,mBAAmB,CAAA;AAAA,MAClD;AAAA,KACF;AAAA,EACF;AAAA,EAEQ,qBAAA,CAAsB,KAAA,EAAe,UAAA,EAAwB,MAAA,EAAyD;AAC5H,IAAA,OAAO,KAAA,CACJ,MAAM,GAAG,CAAA,CACT,OAAO,OAAO,CAAA,CACd,GAAA,CAAI,CAAC,IAAA,KAAS;AACb,MAAA,MAAM,CAAC,GAAA,EAAKC,MAAK,CAAA,GAAI,IAAA,CAAK,MAAM,GAAG,CAAA;AACnC,MAAA,MAAM,IAAIA,MAAAA,IAAS,EAAA;AACnB,MAAA,MAAM,GAAA,GAAM,UAAA,CAAW,QAAA,CAAS,GAAA,CAAI,iBAAA,EAAmB,CAAA,GAAIC,8BAAA,CAAa,IAAA,CAAK,CAAA,EAAG,MAAM,CAAA,GAAI,CAAA;AAC1F,MAAA,OAAO,CAAC,KAAK,GAAG,CAAA;AAAA,IAClB,CAAC,CAAA;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'node:util';\nimport { ISecureConnectionString } from './interfaces';\nimport { SecureString } from './SecureString';\nimport type { IEncryptedValue, InspectFunction, SecureConfig, SecureKeys } from './types';\n\nexport class SecureConnectionString extends ISecureConnectionString {\n readonly #encryptedValue: IEncryptedValue;\n readonly #data: [string, string | SecureString][];\n\n public get secretValue(): string {\n return this.#encryptedValue.getValue();\n }\n\n private constructor(value: string, config: SecureConfig) {\n super();\n this.#encryptedValue = config.encryptionProvider.encrypt(value);\n this.#data = this.parseConnectionString(\n value,\n config.secretKeys.map((x) => x.toLocaleLowerCase()),\n config,\n );\n }\n\n private parseConnectionString(value: string, secretKeys: SecureKeys, config: SecureConfig): [string, string | SecureString][] {\n return value\n .split(';')\n .filter(Boolean)\n .map((pair) => {\n const [key, value] = pair.split('=');\n const v = value ?? '';\n const val = secretKeys.includes(key.toLocaleLowerCase()) ? SecureString.from(v, config) : v;\n return [key, val];\n });\n }\n\n static factory(config: SecureConfig): (value: string) => SecureConnectionString {\n return (value: string) => SecureConnectionString.from(value, config);\n }\n\n public static from<T extends string | null | undefined>(value: T, config: SecureConfig): T extends string ? SecureConnectionString : T {\n if (value === null) {\n return null as T extends string ? SecureConnectionString : T;\n }\n if (value === undefined) {\n return undefined as T extends string ? SecureConnectionString : T;\n }\n return new SecureConnectionString(value, config) as T extends string ? SecureConnectionString : T;\n }\n\n public override toString(): string {\n return this.#data.map(([key, value]) => `${key}=${value}`).join(';');\n }\n\n public override toJSON(): object {\n return Object.fromEntries(this.#data);\n }\n\n public override [util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string {\n if (depth < 0) {\n return '[SecureConnectionString]';\n }\n const newOptions = Object.assign({}, options, {\n depth: options.depth == null ? null : options.depth - 1,\n });\n return inspect(this.toJSON(), newOptions);\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";exports.defaultSecureKeys=["AccessKey","SharedAccessKey","Password","AccountKey","Secret","SecretKey","ApiKey","Token","Key","MasterKey","PrimaryKey","SecondaryKey"];//# sourceMappingURL=chunk-JS7CWWUD.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/defaults.ts"],"names":[],"mappings":";AAEO,IAAM,iBAAA,GAAoB,CAAC,WAAA,EAAa,iBAAA,EAAmB,UAAA,EAAY,YAAA,EAAc,QAAA,EAAU,WAAA,EAAa,QAAA,EAAU,OAAA,EAAS,KAAA,EAAO,WAAA,EAAa,cAAc,cAAc","file":"chunk-JS7CWWUD.cjs","sourcesContent":["import type { SecureKeys } from './types';\n\nexport const defaultSecureKeys = ['AccessKey', 'SharedAccessKey', 'Password', 'AccountKey', 'Secret', 'SecretKey', 'ApiKey', 'Token', 'Key', 'MasterKey', 'PrimaryKey', 'SecondaryKey'] as const satisfies SecureKeys;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("./chunk-PK6SKIKE.cjs"),t=class{static{e.__name(this,"ISecureString")}},c=class{static{e.__name(this,"ISecureConnectionString")}},s=class{static{e.__name(this,"ISecureURL")}},r=class{static{e.__name(this,"ISecureFactory")}};exports.ISecureConnectionString=c,exports.ISecureFactory=r,exports.ISecureString=t,exports.ISecureURL=s;//# sourceMappingURL=chunk-JVM3GGW6.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/interfaces.ts"],"names":["__name"],"mappings":";AAGO,IAAe,gBAAf,MAAmD;AAAA,EAH1D;AAG0D,IAAAA,wBAAA,CAAA,IAAA,EAAA,eAAA,CAAA;AAAA;AAK1D;AAEO,IAAe,0BAAf,MAA6D;AAAA,EAVpE;AAUoE,IAAAA,wBAAA,CAAA,IAAA,EAAA,yBAAA,CAAA;AAAA;AAKpE;AAEO,IAAe,aAAf,MAAgD;AAAA,EAjBvD;AAiBuD,IAAAA,wBAAA,CAAA,IAAA,EAAA,YAAA,CAAA;AAAA;AAKvD;AAEO,IAAe,iBAAf,MAA8B;AAAA,EAxBrC;AAwBqC,IAAAA,wBAAA,CAAA,IAAA,EAAA,gBAAA,CAAA;AAAA;AAIrC","file":"chunk-JVM3GGW6.cjs","sourcesContent":["import util, { type InspectOptions } from 'node:util';\nimport type { BaseObject, InspectFunction } from './types';\n\nexport abstract class ISecureString implements BaseObject {\n public abstract toString(): string;\n public abstract toJSON(): string | object;\n public abstract [util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string;\n public abstract get secretValue(): string;\n}\n\nexport abstract class ISecureConnectionString implements BaseObject {\n public abstract toString(): string;\n public abstract toJSON(): string | object;\n public abstract [util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string;\n public abstract get secretValue(): string;\n}\n\nexport abstract class ISecureURL implements BaseObject {\n public abstract toString(): string;\n public abstract toJSON(): object;\n public abstract [util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string;\n public abstract get secretValue(): URL;\n}\n\nexport abstract class ISecureFactory {\n public abstract string(value: string): ISecureString;\n public abstract connectionString(value: string, secretKeys?: readonly string[]): ISecureConnectionString;\n public abstract url(value: URL): ISecureURL;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=Object.defineProperty;exports.__name=(r,a)=>e(r,"name",{value:a,configurable:!0});//# sourceMappingURL=chunk-PK6SKIKE.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"chunk-PK6SKIKE.cjs"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("./chunk-XVDIOMZD.cjs"),r=require("./chunk-JVM3GGW6.cjs"),t=require("./chunk-PK6SKIKE.cjs");function s(e){return e&&e.__esModule?e:{default:e}}var n=s(require("node:util")),u=class s extends r.ISecureURL{static{t.__name(this,"SecureURL")}#e;#r;get secretValue(){return new URL(this.#e.getValue())}constructor(r,t){super(),this.#e=t.encryptionProvider.encrypt(r.href),this.#r=e.SecureString.from(r.password||null,t)}static factory(e){return r=>s.from(r,e)}static from(e,r){return null===e?null:void 0!==e?new s(e,r):void 0}toString(){const e=this.secretValue,r=new URL(e.href);return null!==this.#r&&(r.password=this.#r.toString()),r.href}toJSON(){const e=this.secretValue,r=new URL(e.href);r.password="";const t=new URLSearchParams(r.searchParams);let s;r.search="",null!==this.#r&&(s=this.#r.toString());const n={href:r.href};return void 0!==s&&(n.password=s),t.size>0&&(n.searchParams=Object.fromEntries(t)),n}[n.default.inspect.custom](e,r,t){if(e<0)return"[SecureURL]";const s=Object.assign({},r,{depth:null==r.depth?null:r.depth-1});return t(this.toJSON(),s)}};exports.SecureURL=u;//# sourceMappingURL=chunk-VQ2XCAJT.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/SecureURL.ts"],"names":["ISecureURL","__name","SecureString","util"],"mappings":"uTAWO,IAAM,SAAA,GAAN,MAAM,UAAA,SAAkBA,4BAAA,CAAW;AAAA,EAX1C;AAW0C,IAAAC,wBAAA,CAAA,IAAA,EAAA,WAAA,CAAA;AAAA;AAAA,EAC/B,eAAA;AAAA,EACA,SAAA;AAAA,EAET,IAAW,WAAA,GAAmB;AAC5B,IAAA,OAAO,IAAI,GAAA,CAAI,IAAA,CAAK,eAAA,CAAgB,UAAU,CAAA;AAAA,EAChD;AAAA,EAEQ,WAAA,CAAY,OAAY,MAAA,EAAsB;AACpD,IAAA,KAAA,EAAM;AACN,IAAA,IAAA,CAAK,eAAA,GAAkB,MAAA,CAAO,kBAAA,CAAmB,OAAA,CAAQ,MAAM,IAAI,CAAA;AACnE,IAAA,IAAA,CAAK,YAAYC,8BAAA,CAAa,IAAA,CAAK,KAAA,CAAM,QAAA,IAAY,MAAM,MAAM,CAAA;AAAA,EACnE;AAAA,EAEA,OAAO,QAAQ,MAAA,EAAkD;AAC/D,IAAA,OAAO,CAAC,KAAA,KAAe,UAAA,CAAU,IAAA,CAAK,OAAO,MAAM,CAAA;AAAA,EACrD;AAAA,EAEA,OAAc,IAAA,CAAuC,KAAA,E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Ae,MAAA,CAAO,WAAA,CAAY,YAAY,CAAA;AAAA,IACvD;AACA,IAAA,OAAO,MAAA;AAAA,EACT;AAAA,EACA,CAAUC,qBAAA,CAAK,OAAA,CAAQ,MAAM,CAAA,CAAE,KAAA,EAAe,SAAyB,OAAA,EAAkC;AACvG,IAAA,IAAI,QAAQ,CAAA,EAAG;AACb,MAAA,OAAO,aAAA;AAAA,IACT;AACA,IAAA,MAAM,UAAA,GAAa,MAAA,CAAO,MAAA,CAAO,IAAI,OAAA,EAAS;AAAA,MAC5C,OAAO,OAAA,CAAQ,KAAA,IAAS,IAAA,GAAO,IAAA,GAAO,QAAQ,KAAA,GAAQ;AAAA,KACvD,CAAA;AACD,IAAA,OAAO,OAAA,CAAQ,IAAA,CAAK,MAAA,EAAO,EAAG,UAAU,CAAA;AAAA,EAC1C;AACF","file":"chunk-VQ2XCAJT.cjs","sourcesContent":["import util, { type InspectOptions } from 'node:util';\nimport { ISecureURL } from './interfaces';\nimport { SecureString } from './SecureString';\nimport type { IEncryptedValue, InspectFunction, SecureConfig } from './types';\n\ntype UrlObject = {\n href: string;\n password?: string;\n searchParams?: Record<string, string>;\n};\n\nexport class SecureURL extends ISecureURL {\n readonly #encryptedValue: IEncryptedValue;\n readonly #password: SecureString | null;\n\n public get secretValue(): URL {\n return new URL(this.#encryptedValue.getValue());\n }\n\n private constructor(value: URL, config: SecureConfig) {\n super();\n this.#encryptedValue = config.encryptionProvider.encrypt(value.href);\n this.#password = SecureString.from(value.password || null, config);\n }\n\n static factory(config: SecureConfig): (value: URL) => ISecureURL {\n return (value: URL) => SecureURL.from(value, config);\n }\n\n public static from<T extends URL | null | undefined>(value: T, config: SecureConfig): T extends URL ? SecureURL : T {\n if (value === null) {\n return null as T extends URL ? SecureURL : T;\n }\n if (value === undefined) {\n return undefined as T extends URL ? SecureURL : T;\n }\n return new SecureURL(value, config) as T extends URL ? SecureURL : T;\n }\n\n override toString(): string {\n const originalUrl = this.secretValue;\n const newUrl = new URL(originalUrl.href);\n if (this.#password !== null) {\n newUrl.password = this.#password.toString();\n }\n return newUrl.href;\n }\n\n override toJSON(): UrlObject {\n const originalUrl = this.secretValue;\n const newUrl = new URL(originalUrl.href);\n newUrl.password = '';\n\n const searchParams = new URLSearchParams(newUrl.searchParams);\n newUrl.search = '';\n\n let password: string | undefined;\n if (this.#password !== null) {\n password = this.#password.toString();\n }\n\n const result: UrlObject = {\n href: newUrl.href,\n };\n if (password !== undefined) {\n result.password = password;\n }\n if (searchParams.size > 0) {\n result.searchParams = Object.fromEntries(searchParams);\n }\n return result;\n }\n override [util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string {\n if (depth < 0) {\n return '[SecureURL]';\n }\n const newOptions = Object.assign({}, options, {\n depth: options.depth == null ? null : options.depth - 1,\n });\n return inspect(this.toJSON(), newOptions);\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var h=require("./chunk-PK6SKIKE.cjs"),e=require("node:crypto"),a={sha256:h.__name(()=>({hash:h.__name(h=>e.createHash("sha256").update(h).digest("hex"),"hash"),prefix:"sha256"}),"sha256"),hs256:h.__name(a=>({hash:h.__name(h=>e.createHmac("sha256",a).update(h).digest("hex"),"hash"),prefix:"hs256"}),"hs256")},s=h.__name(h=>null==h?a.sha256():a.hs256(h),"getAlgorithm"),r=h.__name((h,e)=>{const a=s(e),r=a.hash(h);return`${a.prefix}:${r}`},"hash");exports.hash=r;//# sourceMappingURL=chunk-WZWXGAJN.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/hash.ts"],"names":["__name","createHash","createHmac","hash"],"mappings":"sGAOA,IAAM,UAAA,GAAa;AAAA,EACjB,wBAAQA,wBAAA,CAAA,OAAO;AAAA,IACb,IAAA,kBAAMA,wBAAA,CAAA,CAAC,CAAA,KAAcC,sBAAA,CAAW,QAAQ,CAAA,CAAE,MAAA,CAAO,CAAC,CAAA,CAAE,MAAA,CAAO,KAAK,CAAA,EAA1D,MAAA,CAAA;AAAA,IACN,MAAA,EAAQ;AAAA,GACV,CAAA,EAHQ,QAAA,CAAA;AAAA,EAIR,KAAA,4CAAQ,MAAA,MAAoB;AAAA,IAC1B,IAAA,kBAAMD,wBAAA,CAAA,CAAC,CAAA,KAAcE,sBAAA,CAAW,QAAA,EAAU,MAAM,CAAA,CAAE,MAAA,CAAO,CAAC,CAAA,CAAE,MAAA,CAAO,KAAK,CAAA,EAAlE,MAAA,CAAA;AAAA,IACN,MAAA,EAAQ;AAAA,GACV,CAAA,EAHO,OAAA;AAIT,CAAA;AAEA,IAAM,YAAA,6CAAgB,MAAA,KAAyC;AAC7D,EAAA,OAAO,UAAU,IAAA,GAAO,UAAA,CAAW,QAAO,GAAI,UAAA,CAAW,MAAM,MAAM,CAAA;AACvE,CAAA,EAFqB,cAAA,CAAA;AAId,IAAM,IAAA,mBAAOF,wBAAA,CAAA,CAAC,KAAA,EAAe,MAAA,KAA0B;AAC5D,EAAA,MAAM,GAAA,GAAM,aAAa,MAAM,CAAA;AAC/B,EAAA,MAAMG,KAAAA,GAAO,GAAA,CAAI,IAAA,CAAK,KAAK,CAAA;AAC3B,EAAA,OAAO,CAAA,EAAG,GAAA,CAAI,MAAM,CAAA,CAAA,EAAIA,KAAI,CAAA,CAAA;AAC9B,CAAA,EAJoB,MAAA","file":"chunk-WZWXGAJN.cjs","sourcesContent":["import { createHash, createHmac } from 'node:crypto';\n\ntype HashAlgorithm = {\n hash: (x: string) => string;\n prefix: string;\n};\n\nconst algorithms = {\n sha256: () => ({\n hash: (x: string) => createHash('sha256').update(x).digest('hex'),\n prefix: 'sha256',\n }),\n hs256: (secret: string) => ({\n hash: (x: string) => createHmac('sha256', secret).update(x).digest('hex'),\n prefix: 'hs256',\n }),\n} as const;\n\nconst getAlgorithm = (secret: string | null): HashAlgorithm => {\n return secret == null ? algorithms.sha256() : algorithms.hs256(secret);\n};\n\nexport const hash = (input: string, secret: string | null) => {\n const alg = getAlgorithm(secret);\n const hash = alg.hash(input);\n return `${alg.prefix}:${hash}`;\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("./chunk-JVM3GGW6.cjs"),t=require("./chunk-WZWXGAJN.cjs"),r=require("./chunk-PK6SKIKE.cjs");function n(e){return e&&e.__esModule?e:{default:e}}var u=n(require("node:util")),s=class n extends e.ISecureString{static{r.__name(this,"SecureString")}#e;#t;get secretValue(){return this.#e.getValue()}constructor(e,r){super(),this.#e=r.encryptionProvider.encrypt(e),this.#t=t.hash(e,r.secret)}static factory(e){return t=>n.from(t,e)}static from(e,t){return null===e?null:void 0!==e?new n(e,t):void 0}toString(){return this.#t}toJSON(){return this.toString()}[u.default.inspect.custom](e,t,r){if(e<0)return"[SecureString]";const n=Object.assign({},t,{depth:null==t.depth?null:t.depth-1});return r(this.toJSON(),n)}};exports.SecureString=s;//# sourceMappingURL=chunk-XVDIOMZD.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/SecureString.ts"],"names":["ISecureString","__name","hash","util"],"mappings":"uTAKO,IAAM,YAAA,GAAN,MAAM,aAAA,SAAqBA,+BAAA,CAAc;AAAA,EALhD;AAKgD,IAAAC,wBAAA,CAAA,IAAA,EAAA,cAAA,CAAA;AAAA;AAAA,EACrC,eAAA;AAAA,EACA,KAAA;AAAA,EAET,IAAW,WAAA,GAAsB;AAC/B,IAAA,OAAO,IAAA,CAAK,gBAAgB,QAAA,EAAS;AAAA,EACvC;AAAA,EAEQ,WAAA,CAAY,OAAe,MAAA,EAAsB;AACvD,IAAA,KAAA,EAAM;AACN,IAAA,IAAA,CAAK,eAAA,GAAkB,MAAA,CAAO,kBAAA,CAAmB,OAAA,CAAQ,KAAK,CAAA;AAC9D,IAAA,IAAA,CAAK,KAAA,GAAQC,sBAAA,CAAK,KAAA,EAAO,MAAA,CAAO,MAAM,CAAA;AAAA,EACxC;AAAA,EAEA,OAAO,QAAQ,MAAA,EAAuD;AACpE,IAAA,OAAO,CAAC,KAAA,KAAkB,aAAA,CAAa,IAAA,CAAK,OAAO,MAAM,CAAA;AAAA,EAC3D;AAAA,EAEA,OAAc,IAAA,CAA0C,KAAA,EAAU,MAAA,EAA2D;AAC3H,IAAA,IAAI,UAAU,IAAA,EAAM;AAClB,MAAA,OAAO,IAAA;AAAA,IACT;AACA,IAAA,IAAI,UAAU,MAAA,EAAW;AACvB,MAAA,OAAO,MAAA;AAAA,IACT;AACA,IAAA,OAAO,IAAI,aAAA,CAAa,KAAA,EAAO,MAAM,CAAA;AAAA,EACvC;AAAA,EAEgB,QAAA,GAAW;AACzB,IAAA,OAAO,IAAA,CAAK,KAAA;AAAA,EACd;AAAA,EACgB,MAAA,GAAS;AACvB,IAAA,OAAO,KAAK,QAAA,EAAS;AAAA,EACvB;AAAA,EACA,CAAUC,qBAAA,CAAK,OAAA,CAAQ,MAAM,CAAA,CAAE,KAAA,EAAe,SAAyB,OAAA,EAAkC;AACvG,IAAA,IAAI,QAAQ,CAAA,EAAG;AACb,MAAA,OAAO,gBAAA;AAAA,IACT;AACA,IAAA,MAAM,UAAA,GAAa,MAAA,CAAO,MAAA,CAAO,IAAI,OAAA,EAAS;AAAA,MAC5C,OAAO,OAAA,CAAQ,KAAA,IAAS,IAAA,GAAO,IAAA,GAAO,QAAQ,KAAA,GAAQ;AAAA,KACvD,CAAA;AACD,IAAA,OAAO,OAAA,CAAQ,IAAA,CAAK,MAAA,EAAO,EAAG,UAAU,CAAA;AAAA,EAC1C;AACF","file":"chunk-XVDIOMZD.cjs","sourcesContent":["import util, { type InspectOptions } from 'node:util';\nimport { hash } from './hash';\nimport { ISecureString } from './interfaces';\nimport type { IEncryptedValue, InspectFunction, SecureConfig } from './types';\n\nexport class SecureString extends ISecureString {\n readonly #encryptedValue: IEncryptedValue;\n readonly #hash: string;\n\n public get secretValue(): string {\n return this.#encryptedValue.getValue();\n }\n\n private constructor(value: string, config: SecureConfig) {\n super();\n this.#encryptedValue = config.encryptionProvider.encrypt(value);\n this.#hash = hash(value, config.secret);\n }\n\n static factory(config: SecureConfig): (value: string) => SecureString {\n return (value: string) => SecureString.from(value, config);\n }\n\n public static from<T extends string | null | undefined>(value: T, config: SecureConfig): T extends string ? SecureString : T {\n if (value === null) {\n return null as T extends string ? SecureString : T;\n }\n if (value === undefined) {\n return undefined as T extends string ? SecureString : T;\n }\n return new SecureString(value, config) as T extends string ? SecureString : T;\n }\n\n public override toString() {\n return this.#hash;\n }\n public override toJSON() {\n return this.toString();\n }\n override [util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string {\n if (depth < 0) {\n return '[SecureString]';\n }\n const newOptions = Object.assign({}, options, {\n depth: options.depth == null ? null : options.depth - 1,\n });\n return inspect(this.toJSON(), newOptions);\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("./chunk-7PP3CDDK.cjs");require("./chunk-FKX4J4Q2.cjs"),require("./chunk-J7CRMQ5Z.cjs"),require("./chunk-VQ2XCAJT.cjs"),require("./chunk-XVDIOMZD.cjs"),require("./chunk-JVM3GGW6.cjs"),require("./chunk-JS7CWWUD.cjs"),require("./chunk-WZWXGAJN.cjs"),require("./chunk-PK6SKIKE.cjs"),Object.defineProperty(exports,"createFactory",{enumerable:!0,get:function(){return e.createFactory}}),Object.defineProperty(exports,"defaultEncryptionProvider",{enumerable:!0,get:function(){return e.defaultEncryptionProvider}});//# sourceMappingURL=createFactory.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"createFactory.cjs"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ISecureFactory } from './interfaces.cjs';
|
|
2
|
+
import { IEncryptionProvider, SecureConfig } from './types.cjs';
|
|
3
|
+
import 'node:util';
|
|
4
|
+
|
|
5
|
+
declare const defaultEncryptionProvider: IEncryptionProvider;
|
|
6
|
+
declare const createFactory: (options?: Partial<SecureConfig>) => ISecureFactory;
|
|
7
|
+
|
|
8
|
+
export { createFactory, defaultEncryptionProvider };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("./chunk-JS7CWWUD.cjs");require("./chunk-PK6SKIKE.cjs"),Object.defineProperty(exports,"defaultSecureKeys",{enumerable:!0,get:function(){return e.defaultSecureKeys}});//# sourceMappingURL=defaults.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"defaults.cjs"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("./chunk-WZWXGAJN.cjs");require("./chunk-PK6SKIKE.cjs"),Object.defineProperty(exports,"hash",{enumerable:!0,get:function(){return e.hash}});//# sourceMappingURL=hash.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"hash.cjs"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("./chunk-7PP3CDDK.cjs"),r=require("./chunk-FKX4J4Q2.cjs");require("./chunk-J7CRMQ5Z.cjs"),require("./chunk-VQ2XCAJT.cjs"),require("./chunk-XVDIOMZD.cjs");var t=require("./chunk-JVM3GGW6.cjs"),n=require("./chunk-JS7CWWUD.cjs");require("./chunk-WZWXGAJN.cjs"),require("./chunk-PK6SKIKE.cjs"),Object.defineProperty(exports,"createFactory",{enumerable:!0,get:function(){return e.createFactory}}),Object.defineProperty(exports,"EncryptedValue",{enumerable:!0,get:function(){return r.EncryptedValue}}),Object.defineProperty(exports,"ISecureConnectionString",{enumerable:!0,get:function(){return t.ISecureConnectionString}}),Object.defineProperty(exports,"ISecureString",{enumerable:!0,get:function(){return t.ISecureString}}),Object.defineProperty(exports,"ISecureURL",{enumerable:!0,get:function(){return t.ISecureURL}}),Object.defineProperty(exports,"defaultSecureKeys",{enumerable:!0,get:function(){return n.defaultSecureKeys}});//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.cjs"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { createFactory } from './createFactory.cjs';
|
|
2
|
+
export { defaultSecureKeys } from './defaults.cjs';
|
|
3
|
+
export { EncryptedValue } from './EncryptedValue.cjs';
|
|
4
|
+
export { ISecureConnectionString, ISecureString, ISecureURL } from './interfaces.cjs';
|
|
5
|
+
export { SecureConfig } from './types.cjs';
|
|
6
|
+
import 'node:util';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("./chunk-JVM3GGW6.cjs");require("./chunk-PK6SKIKE.cjs"),Object.defineProperty(exports,"ISecureConnectionString",{enumerable:!0,get:function(){return e.ISecureConnectionString}}),Object.defineProperty(exports,"ISecureFactory",{enumerable:!0,get:function(){return e.ISecureFactory}}),Object.defineProperty(exports,"ISecureString",{enumerable:!0,get:function(){return e.ISecureString}}),Object.defineProperty(exports,"ISecureURL",{enumerable:!0,get:function(){return e.ISecureURL}});//# sourceMappingURL=interfaces.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"interfaces.cjs"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import util, { InspectOptions } from 'node:util';
|
|
2
|
+
import { BaseObject, InspectFunction } from './types.cjs';
|
|
3
|
+
|
|
4
|
+
declare abstract class ISecureString implements BaseObject {
|
|
5
|
+
abstract toString(): string;
|
|
6
|
+
abstract toJSON(): string | object;
|
|
7
|
+
abstract [util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string;
|
|
8
|
+
abstract get secretValue(): string;
|
|
9
|
+
}
|
|
10
|
+
declare abstract class ISecureConnectionString implements BaseObject {
|
|
11
|
+
abstract toString(): string;
|
|
12
|
+
abstract toJSON(): string | object;
|
|
13
|
+
abstract [util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string;
|
|
14
|
+
abstract get secretValue(): string;
|
|
15
|
+
}
|
|
16
|
+
declare abstract class ISecureURL implements BaseObject {
|
|
17
|
+
abstract toString(): string;
|
|
18
|
+
abstract toJSON(): object;
|
|
19
|
+
abstract [util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string;
|
|
20
|
+
abstract get secretValue(): URL;
|
|
21
|
+
}
|
|
22
|
+
declare abstract class ISecureFactory {
|
|
23
|
+
abstract string(value: string): ISecureString;
|
|
24
|
+
abstract connectionString(value: string, secretKeys?: readonly string[]): ISecureConnectionString;
|
|
25
|
+
abstract url(value: URL): ISecureURL;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { ISecureConnectionString, ISecureFactory, ISecureString, ISecureURL };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var s=require("./chunk-PK6SKIKE.cjs"),e=class{static{s.__name(this,"BaseObject")}};exports.BaseObject=e;//# sourceMappingURL=types.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/types.ts"],"names":["__name"],"mappings":";AAIO,IAAe,aAAf,MAA0B;AAAA,EAJjC;AAIiC,IAAAA,wBAAA,CAAA,IAAA,EAAA,YAAA,CAAA;AAAA;AAIjC","file":"types.cjs","sourcesContent":["import util, { type InspectOptions } from 'node:util';\n\nexport type InspectFunction = typeof util.inspect;\n\nexport abstract class BaseObject {\n public abstract toString(): string;\n public abstract toJSON(): string | object;\n public abstract [util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string;\n}\n\nexport type SecureKeys = readonly string[];\n\nexport interface IEncryptedValue {\n getValue(): string;\n toString(): string;\n toJSON(): object;\n}\n\nexport interface IEncryptionProvider {\n encrypt(value: string): IEncryptedValue;\n}\n\nexport interface SecureConfig {\n secret: string | null;\n encryptionProvider: IEncryptionProvider;\n secretKeys: SecureKeys;\n}\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import util, { InspectOptions } from 'node:util';
|
|
2
|
+
|
|
3
|
+
type InspectFunction = typeof util.inspect;
|
|
4
|
+
declare abstract class BaseObject {
|
|
5
|
+
abstract toString(): string;
|
|
6
|
+
abstract toJSON(): string | object;
|
|
7
|
+
abstract [util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string;
|
|
8
|
+
}
|
|
9
|
+
type SecureKeys = readonly string[];
|
|
10
|
+
interface IEncryptedValue {
|
|
11
|
+
getValue(): string;
|
|
12
|
+
toString(): string;
|
|
13
|
+
toJSON(): object;
|
|
14
|
+
}
|
|
15
|
+
interface IEncryptionProvider {
|
|
16
|
+
encrypt(value: string): IEncryptedValue;
|
|
17
|
+
}
|
|
18
|
+
interface SecureConfig {
|
|
19
|
+
secret: string | null;
|
|
20
|
+
encryptionProvider: IEncryptionProvider;
|
|
21
|
+
secretKeys: SecureKeys;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { BaseObject, type IEncryptedValue, type IEncryptionProvider, type InspectFunction, type SecureConfig, type SecureKeys };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare class EncryptedValue {
|
|
2
|
+
private readonly encryptedData;
|
|
3
|
+
private readonly iv;
|
|
4
|
+
private readonly authTag;
|
|
5
|
+
private readonly key;
|
|
6
|
+
constructor(value: string);
|
|
7
|
+
getValue(): string;
|
|
8
|
+
toString(): string;
|
|
9
|
+
toJSON(): object;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { EncryptedValue };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{EncryptedValue}from"./chunk-CGPJ25IS.js";import"./chunk-7QVYU63E.js";//# sourceMappingURL=EncryptedValue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"EncryptedValue.js"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import util, { InspectOptions } from 'node:util';
|
|
2
|
+
import { ISecureConnectionString } from './interfaces.js';
|
|
3
|
+
import { SecureConfig, InspectFunction } from './types.js';
|
|
4
|
+
|
|
5
|
+
declare class SecureConnectionString extends ISecureConnectionString {
|
|
6
|
+
#private;
|
|
7
|
+
get secretValue(): string;
|
|
8
|
+
private constructor();
|
|
9
|
+
private parseConnectionString;
|
|
10
|
+
static factory(config: SecureConfig): (value: string) => SecureConnectionString;
|
|
11
|
+
static from<T extends string | null | undefined>(value: T, config: SecureConfig): T extends string ? SecureConnectionString : T;
|
|
12
|
+
toString(): string;
|
|
13
|
+
toJSON(): object;
|
|
14
|
+
[util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { SecureConnectionString };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{SecureConnectionString}from"./chunk-S3UXVGVK.js";import"./chunk-JAXX5FG7.js";import"./chunk-XICVVAG4.js";import"./chunk-GJXVQ2LL.js";import"./chunk-7QVYU63E.js";//# sourceMappingURL=SecureConnectionString.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"SecureConnectionString.js"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import util, { InspectOptions } from 'node:util';
|
|
2
|
+
import { ISecureString } from './interfaces.js';
|
|
3
|
+
import { SecureConfig, InspectFunction } from './types.js';
|
|
4
|
+
|
|
5
|
+
declare class SecureString extends ISecureString {
|
|
6
|
+
#private;
|
|
7
|
+
get secretValue(): string;
|
|
8
|
+
private constructor();
|
|
9
|
+
static factory(config: SecureConfig): (value: string) => SecureString;
|
|
10
|
+
static from<T extends string | null | undefined>(value: T, config: SecureConfig): T extends string ? SecureString : T;
|
|
11
|
+
toString(): string;
|
|
12
|
+
toJSON(): string;
|
|
13
|
+
[util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { SecureString };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{SecureString}from"./chunk-JAXX5FG7.js";import"./chunk-XICVVAG4.js";import"./chunk-GJXVQ2LL.js";import"./chunk-7QVYU63E.js";//# sourceMappingURL=SecureString.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"SecureString.js"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import util, { InspectOptions } from 'node:util';
|
|
2
|
+
import { ISecureURL } from './interfaces.js';
|
|
3
|
+
import { SecureConfig, InspectFunction } from './types.js';
|
|
4
|
+
|
|
5
|
+
type UrlObject = {
|
|
6
|
+
href: string;
|
|
7
|
+
password?: string;
|
|
8
|
+
searchParams?: Record<string, string>;
|
|
9
|
+
};
|
|
10
|
+
declare class SecureURL extends ISecureURL {
|
|
11
|
+
#private;
|
|
12
|
+
get secretValue(): URL;
|
|
13
|
+
private constructor();
|
|
14
|
+
static factory(config: SecureConfig): (value: URL) => ISecureURL;
|
|
15
|
+
static from<T extends URL | null | undefined>(value: T, config: SecureConfig): T extends URL ? SecureURL : T;
|
|
16
|
+
toString(): string;
|
|
17
|
+
toJSON(): UrlObject;
|
|
18
|
+
[util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { SecureURL };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{SecureURL}from"./chunk-TGJY6ZQ7.js";import"./chunk-JAXX5FG7.js";import"./chunk-XICVVAG4.js";import"./chunk-GJXVQ2LL.js";import"./chunk-7QVYU63E.js";//# sourceMappingURL=SecureURL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"SecureURL.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=Object.defineProperty,r=(r,a)=>e(r,"name",{value:a,configurable:!0});export{r as __name};//# sourceMappingURL=chunk-7QVYU63E.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"chunk-7QVYU63E.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{__name as t}from"./chunk-7QVYU63E.js";import{randomBytes as e,createCipheriv as a,createDecipheriv as r}from"node:crypto";var c=class{static{t(this,"EncryptedValue")}encryptedData;iv;authTag;key;constructor(t){this.key=e(32),this.iv=e(16);const r=a("aes-256-gcm",this.key,this.iv),c=[];c.push(r.update(t,"utf8")),c.push(r.final()),this.encryptedData=Buffer.concat(c),this.authTag=r.getAuthTag()}getValue(){const t=r("aes-256-gcm",this.key,this.iv);t.setAuthTag(this.authTag);try{const e=[];return e.push(t.update(this.encryptedData)),e.push(t.final()),Buffer.concat(e).toString("utf8")}catch(t){throw new Error("Failed to decrypt value: Invalid key or corrupted data")}}toString(){return"[EncryptedValue]"}toJSON(){return{type:"EncryptedValue",encrypted:!0}}};export{c as EncryptedValue};//# sourceMappingURL=chunk-CGPJ25IS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/EncryptedValue.ts"],"names":[],"mappings":"+GAEO,IAAM,iBAAN,MAAqB;AAAA,EAF5B;AAE4B,IAAA,MAAA,CAAA,IAAA,EAAA,gBAAA,CAAA;AAAA;AAAA,EACT,aAAA;AAAA,EACA,EAAA;AAAA,EACA,OAAA;AAAA,EACA,GAAA;AAAA,EAEV,YAAY,KAAA,EAAe;AAChC,IAAA,IAAA,CAAK,GAAA,GAAM,YAAY,EAAE,CAAA;AACzB,IAAA,IAAA,CAAK,EAAA,GAAK,YAAY,EAAE,CAAA;AAExB,IAAA,MAAM,SAAS,cAAA,CAAe,aAAA,EAAe,IAAA,CAAK,GAAA,EAAK,KAAK,EAAE,CAAA;AAE9D,IAAA,MAAM,kBAA4B,EAAC;AACnC,IAAA,eAAA,CAAgB,IAAA,CAAK,MAAA,CAAO,MAAA,CAAO,KAAA,EAAO,MAAM,CAAC,CAAA;AACjD,IAAA,eAAA,CAAgB,IAAA,CAAK,MAAA,CAAO,KAAA,EAAO,CAAA;AAEnC,IAAA,IAAA,CAAK,aAAA,GAAgB,MAAA,CAAO,MAAA,CAAO,eAAe,CAAA;AAClD,IAAA,IAAA,CAAK,OAAA,GAAU,OAAO,UAAA,EAAW;AAAA,EACnC;AAAA,EAEO,QAAA,GAAmB;AACxB,IAAA,MAAM,WAAW,gBAAA,CAAiB,aAAA,EAAe,IAAA,CAAK,GAAA,EAAK,KAAK,EAAE,CAAA;AAClE,IAAA,QAAA,CAAS,UAAA,CAAW,KAAK,OAAO,CAAA;AAEhC,IAAA,IAAI;AACF,MAAA,MAAM,kBAA4B,EAAC;AACnC,MAAA,eAAA,CAAgB,IAAA,CAAK,QAAA,CAAS,MAAA,CAAO,IAAA,CAAK,aAAa,CAAC,CAAA;AACxD,MAAA,eAAA,CAAgB,IAAA,CAAK,QAAA,CAAS,KAAA,EAAO,CAAA;AAErC,MAAA,OAAO,MAAA,CAAO,MAAA,CAAO,eAAe,CAAA,CAAE,SAAS,MAAM,CAAA;AAAA,IACvD,SAAS,CAAA,EAAG;AAEV,MAAA,MAAM,IAAI,MAAM,wDAAwD,CAAA;AAAA,IAC1E;AAAA,EACF;AAAA,EAEO,QAAA,GAAmB;AACxB,IAAA,OAAO,kBAAA;AAAA,EACT;AAAA,EAEO,MAAA,GAAiB;AACtB,IAAA,OAAO,EAAE,IAAA,EAAM,gBAAA,EAAkB,SAAA,EAAW,IAAA,EAAK;AAAA,EACnD;AACF","file":"chunk-CGPJ25IS.js","sourcesContent":["import { createCipheriv, createDecipheriv, randomBytes } from 'node:crypto';\n\nexport class EncryptedValue {\n private readonly encryptedData: Buffer;\n private readonly iv: Buffer;\n private readonly authTag: Buffer;\n private readonly key: Buffer;\n\n public constructor(value: string) {\n this.key = randomBytes(32);\n this.iv = randomBytes(16);\n\n const cipher = createCipheriv('aes-256-gcm', this.key, this.iv);\n\n const encryptedChunks: Buffer[] = [];\n encryptedChunks.push(cipher.update(value, 'utf8'));\n encryptedChunks.push(cipher.final());\n\n this.encryptedData = Buffer.concat(encryptedChunks);\n this.authTag = cipher.getAuthTag();\n }\n\n public getValue(): string {\n const decipher = createDecipheriv('aes-256-gcm', this.key, this.iv);\n decipher.setAuthTag(this.authTag);\n\n try {\n const decryptedChunks: Buffer[] = [];\n decryptedChunks.push(decipher.update(this.encryptedData));\n decryptedChunks.push(decipher.final());\n\n return Buffer.concat(decryptedChunks).toString('utf8');\n } catch (_) {\n // Hide internal error details\n throw new Error('Failed to decrypt value: Invalid key or corrupted data');\n }\n }\n\n public toString(): string {\n return '[EncryptedValue]';\n }\n\n public toJSON(): object {\n return { type: 'EncryptedValue', encrypted: true };\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=["AccessKey","SharedAccessKey","Password","AccountKey","Secret","SecretKey","ApiKey","Token","Key","MasterKey","PrimaryKey","SecondaryKey"];export{e as defaultSecureKeys};//# sourceMappingURL=chunk-FUGQ3OFQ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/defaults.ts"],"names":[],"mappings":";AAEO,IAAM,iBAAA,GAAoB,CAAC,WAAA,EAAa,iBAAA,EAAmB,UAAA,EAAY,YAAA,EAAc,QAAA,EAAU,WAAA,EAAa,QAAA,EAAU,OAAA,EAAS,KAAA,EAAO,WAAA,EAAa,cAAc,cAAc","file":"chunk-FUGQ3OFQ.js","sourcesContent":["import type { SecureKeys } from './types';\n\nexport const defaultSecureKeys = ['AccessKey', 'SharedAccessKey', 'Password', 'AccountKey', 'Secret', 'SecretKey', 'ApiKey', 'Token', 'Key', 'MasterKey', 'PrimaryKey', 'SecondaryKey'] as const satisfies SecureKeys;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{__name as h}from"./chunk-7QVYU63E.js";import{createHmac as s,createHash as a}from"node:crypto";var e={sha256:h(()=>({hash:h(h=>a("sha256").update(h).digest("hex"),"hash"),prefix:"sha256"}),"sha256"),hs256:h(a=>({hash:h(h=>s("sha256",a).update(h).digest("hex"),"hash"),prefix:"hs256"}),"hs256")},r=h(h=>null==h?e.sha256():e.hs256(h),"getAlgorithm"),t=h((h,s)=>{const a=r(s),e=a.hash(h);return`${a.prefix}:${e}`},"hash");export{t as hash};//# sourceMappingURL=chunk-GJXVQ2LL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/hash.ts"],"names":["hash"],"mappings":"yFAOA,IAAM,UAAA,GAAa;AAAA,EACjB,wBAAQ,MAAA,CAAA,OAAO;AAAA,IACb,IAAA,kBAAM,MAAA,CAAA,CAAC,CAAA,KAAc,UAAA,CAAW,QAAQ,CAAA,CAAE,MAAA,CAAO,CAAC,CAAA,CAAE,MAAA,CAAO,KAAK,CAAA,EAA1D,MAAA,CAAA;AAAA,IACN,MAAA,EAAQ;AAAA,GACV,CAAA,EAHQ,QAAA,CAAA;AAAA,EAIR,KAAA,0BAAQ,MAAA,MAAoB;AAAA,IAC1B,IAAA,kBAAM,MAAA,CAAA,CAAC,CAAA,KAAc,UAAA,CAAW,QAAA,EAAU,MAAM,CAAA,CAAE,MAAA,CAAO,CAAC,CAAA,CAAE,MAAA,CAAO,KAAK,CAAA,EAAlE,MAAA,CAAA;AAAA,IACN,MAAA,EAAQ;AAAA,GACV,CAAA,EAHO,OAAA;AAIT,CAAA;AAEA,IAAM,YAAA,2BAAgB,MAAA,KAAyC;AAC7D,EAAA,OAAO,UAAU,IAAA,GAAO,UAAA,CAAW,QAAO,GAAI,UAAA,CAAW,MAAM,MAAM,CAAA;AACvE,CAAA,EAFqB,cAAA,CAAA;AAId,IAAM,IAAA,mBAAO,MAAA,CAAA,CAAC,KAAA,EAAe,MAAA,KAA0B;AAC5D,EAAA,MAAM,GAAA,GAAM,aAAa,MAAM,CAAA;AAC/B,EAAA,MAAMA,KAAAA,GAAO,GAAA,CAAI,IAAA,CAAK,KAAK,CAAA;AAC3B,EAAA,OAAO,CAAA,EAAG,GAAA,CAAI,MAAM,CAAA,CAAA,EAAIA,KAAI,CAAA,CAAA;AAC9B,CAAA,EAJoB,MAAA","file":"chunk-GJXVQ2LL.js","sourcesContent":["import { createHash, createHmac } from 'node:crypto';\n\ntype HashAlgorithm = {\n hash: (x: string) => string;\n prefix: string;\n};\n\nconst algorithms = {\n sha256: () => ({\n hash: (x: string) => createHash('sha256').update(x).digest('hex'),\n prefix: 'sha256',\n }),\n hs256: (secret: string) => ({\n hash: (x: string) => createHmac('sha256', secret).update(x).digest('hex'),\n prefix: 'hs256',\n }),\n} as const;\n\nconst getAlgorithm = (secret: string | null): HashAlgorithm => {\n return secret == null ? algorithms.sha256() : algorithms.hs256(secret);\n};\n\nexport const hash = (input: string, secret: string | null) => {\n const alg = getAlgorithm(secret);\n const hash = alg.hash(input);\n return `${alg.prefix}:${hash}`;\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{ISecureString as t}from"./chunk-XICVVAG4.js";import{hash as r}from"./chunk-GJXVQ2LL.js";import{__name as e}from"./chunk-7QVYU63E.js";import n from"node:util";var s=class s extends t{static{e(this,"SecureString")}#t;#r;get secretValue(){return this.#t.getValue()}constructor(t,e){super(),this.#t=e.encryptionProvider.encrypt(t),this.#r=r(t,e.secret)}static factory(t){return r=>s.from(r,t)}static from(t,r){return null===t?null:void 0!==t?new s(t,r):void 0}toString(){return this.#r}toJSON(){return this.toString()}[n.inspect.custom](t,r,e){if(t<0)return"[SecureString]";const n=Object.assign({},r,{depth:null==r.depth?null:r.depth-1});return e(this.toJSON(),n)}};export{s as SecureString};//# sourceMappingURL=chunk-JAXX5FG7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/SecureString.ts"],"names":[],"mappings":"4JAKO,IAAM,YAAA,GAAN,MAAM,aAAA,SAAqB,aAAA,CAAc;AAAA,EALhD;AAKgD,IAAA,MAAA,CAAA,IAAA,EAAA,cAAA,CAAA;AAAA;AAAA,EACrC,eAAA;AAAA,EACA,KAAA;AAAA,EAET,IAAW,WAAA,GAAsB;AAC/B,IAAA,OAAO,IAAA,C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O,EAAG,UAAU,CAAA;AAAA,EAC1C;AACF","file":"chunk-JAXX5FG7.js","sourcesContent":["import util, { type InspectOptions } from 'node:util';\nimport { hash } from './hash';\nimport { ISecureString } from './interfaces';\nimport type { IEncryptedValue, InspectFunction, SecureConfig } from './types';\n\nexport class SecureString extends ISecureString {\n readonly #encryptedValue: IEncryptedValue;\n readonly #hash: string;\n\n public get secretValue(): string {\n return this.#encryptedValue.getValue();\n }\n\n private constructor(value: string, config: SecureConfig) {\n super();\n this.#encryptedValue = config.encryptionProvider.encrypt(value);\n this.#hash = hash(value, config.secret);\n }\n\n static factory(config: SecureConfig): (value: string) => SecureString {\n return (value: string) => SecureString.from(value, config);\n }\n\n public static from<T extends string | null | undefined>(value: T, config: SecureConfig): T extends string ? SecureString : T {\n if (value === null) {\n return null as T extends string ? SecureString : T;\n }\n if (value === undefined) {\n return undefined as T extends string ? SecureString : T;\n }\n return new SecureString(value, config) as T extends string ? SecureString : T;\n }\n\n public override toString() {\n return this.#hash;\n }\n public override toJSON() {\n return this.toString();\n }\n override [util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string {\n if (depth < 0) {\n return '[SecureString]';\n }\n const newOptions = Object.assign({}, options, {\n depth: options.depth == null ? null : options.depth - 1,\n });\n return inspect(this.toJSON(), newOptions);\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{EncryptedValue as r}from"./chunk-CGPJ25IS.js";import{SecureConnectionString as t}from"./chunk-S3UXVGVK.js";import{SecureURL as o}from"./chunk-TGJY6ZQ7.js";import{SecureString as c}from"./chunk-JAXX5FG7.js";import{defaultSecureKeys as e}from"./chunk-FUGQ3OFQ.js";import{__name as n}from"./chunk-7QVYU63E.js";var s={encrypt:n(t=>new r(t),"encrypt")},i=n(r=>{const n={secret:r?.secret??null,encryptionProvider:r?.encryptionProvider??s,secretKeys:r?.secretKeys??e};return{string:c.factory(n),connectionString:t.factory(n),url:o.factory(n)}},"createFactory");export{i as createFactory,s as defaultEncryptionProvider};//# sourceMappingURL=chunk-NWPDBO55.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/createFactory.ts"],"names":[],"mappings":";AAQO,IAAM,yBAAA,GAAiD;AAAA,EAC5D,yBAAS,MAAA,CAAA,CAAC,KAAA,KAAkB,IAAI,cAAA,CAAe,KAAK,CAAA,EAA3C,SAAA;AACX;AAEO,IAAM,aAAA,2BAAiB,OAAA,KAAoD;AAChF,EAAA,MAAM,MAAA,GAAuB;AAAA,IAC3B,MAAA,EAAQ,SAAS,MAAA,IAAU,IAAA;AAAA,IAC3B,kBAAA,EAAoB,SAAS,kBAAA,IAAsB,yBAAA;AAAA,IACnD,UAAA,EAAY,SAAS,UAAA,IAAc;AAAA,GACrC;AAEA,EAAA,OAAO;AAAA,IACL,MAAA,EAAQ,YAAA,CAAa,OAAA,CAAQ,MAAM,CAAA;AAAA,IACnC,gBAAA,EAAkB,sBAAA,CAAuB,OAAA,CAAQ,MAAM,CAAA;AAAA,IACvD,GAAA,EAAK,SAAA,CAAU,OAAA,CAAQ,MAAM;AAAA,GAC/B;AACF,CAAA,EAZ6B,eAAA","file":"chunk-NWPDBO55.js","sourcesContent":["import { defaultSecureKeys } from './defaults';\nimport { EncryptedValue } from './EncryptedValue';\nimport type { ISecureFactory } from './interfaces';\nimport { SecureConnectionString } from './SecureConnectionString';\nimport { SecureString } from './SecureString';\nimport { SecureURL } from './SecureURL';\nimport type { IEncryptionProvider, SecureConfig } from './types';\n\nexport const defaultEncryptionProvider: IEncryptionProvider = {\n encrypt: (value: string) => new EncryptedValue(value),\n};\n\nexport const createFactory = (options?: Partial<SecureConfig>): ISecureFactory => {\n const config: SecureConfig = {\n secret: options?.secret ?? null,\n encryptionProvider: options?.encryptionProvider ?? defaultEncryptionProvider,\n secretKeys: options?.secretKeys ?? defaultSecureKeys,\n };\n\n return {\n string: SecureString.factory(config),\n connectionString: SecureConnectionString.factory(config),\n url: SecureURL.factory(config),\n };\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{SecureString as t}from"./chunk-JAXX5FG7.js";import{ISecureConnectionString as e}from"./chunk-XICVVAG4.js";import{__name as r}from"./chunk-7QVYU63E.js";import n from"node:util";var o=class o extends e{static{r(this,"SecureConnectionString")}#t;#e;get secretValue(){return this.#t.getValue()}constructor(t,e){super(),this.#t=e.encryptionProvider.encrypt(t),this.#e=this.parseConnectionString(t,e.secretKeys.map(t=>t.toLocaleLowerCase()),e)}parseConnectionString(e,r,n){return e.split(";").filter(Boolean).map(e=>{const[o,i]=e.split("="),s=i??"",c=r.includes(o.toLocaleLowerCase())?t.from(s,n):s;return[o,c]})}static factory(t){return e=>o.from(e,t)}static from(t,e){return null===t?null:void 0!==t?new o(t,e):void 0}toString(){return this.#e.map(([t,e])=>`${t}=${e}`).join(";")}toJSON(){return Object.fromEntries(this.#e)}[n.inspect.custom](t,e,r){if(t<0)return"[SecureConnectionString]";const n=Object.assign({},e,{depth:null==e.depth?null:e.depth-1});return r(this.toJSON(),n)}};export{o as SecureConnectionString};//# sourceMappingURL=chunk-S3UXVGVK.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/SecureConnectionString.ts"],"names":["value"],"mappings":"8KAKO,IAAM,sBAAA,GAAN,MAAM,uBAAA,SAA+B,uBAAA,CAAwB;AAAA,EALpE;AAKoE,IAAA,MAAA,CAAA,IAAA,EAAA,wBAAA,CAAA;AAAA;AAAA,EACzD,eAAA;AAAA,EACA,KAAA;AAAA,EAET,IAAW,WAAA,GAAsB;AAC/B,IAAA,OAAO,IAAA,CAAK,gBAAgB,QAAA,EAAS;AAAA,EACvC;AAAA,EAEQ,WAAA,CAAY,OAAe,MAAA,EAAsB;AACvD,IAAA,KAAA,EAAM;AACN,IAAA,IAAA,CAAK,eAAA,GAAkB,MAAA,CAAO,kBAAA,CAAmB,OAAA,CAAQ,KAAK,CAAA;AAC9D,IAAA,IAAA,CAAK,QAAQ,IA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CAAA,CAAA,EAAI,KAAK,CAAA,CAAE,CAAA,CAAE,KAAK,GAAG,CAAA;AAAA,EACrE;AAAA,EAEgB,MAAA,GAAiB;AAC/B,IAAA,OAAO,MAAA,CAAO,WAAA,CAAY,IAAA,CAAK,KAAK,CAAA;AAAA,EACtC;AAAA,EAEA,CAAiB,IAAA,CAAK,OAAA,CAAQ,MAAM,CAAA,CAAE,KAAA,EAAe,SAAyB,OAAA,EAAkC;AAC9G,IAAA,IAAI,QAAQ,CAAA,EAAG;AACb,MAAA,OAAO,0BAAA;AAAA,IACT;AACA,IAAA,MAAM,UAAA,GAAa,MAAA,CAAO,MAAA,CAAO,IAAI,OAAA,EAAS;AAAA,MAC5C,OAAO,OAAA,CAAQ,KAAA,IAAS,IAAA,GAAO,IAAA,GAAO,QAAQ,KAAA,GAAQ;AAAA,KACvD,CAAA;AACD,IAAA,OAAO,OAAA,CAAQ,IAAA,CAAK,MAAA,EAAO,EAAG,UAAU,CAAA;AAAA,EAC1C;AACF","file":"chunk-S3UXVGVK.js","sourcesContent":["import util, { type InspectOptions } from 'node:util';\nimport { ISecureConnectionString } from './interfaces';\nimport { SecureString } from './SecureString';\nimport type { IEncryptedValue, InspectFunction, SecureConfig, SecureKeys } from './types';\n\nexport class SecureConnectionString extends ISecureConnectionString {\n readonly #encryptedValue: IEncryptedValue;\n readonly #data: [string, string | SecureString][];\n\n public get secretValue(): string {\n return this.#encryptedValue.getValue();\n }\n\n private constructor(value: string, config: SecureConfig) {\n super();\n this.#encryptedValue = config.encryptionProvider.encrypt(value);\n this.#data = this.parseConnectionString(\n value,\n config.secretKeys.map((x) => x.toLocaleLowerCase()),\n config,\n );\n }\n\n private parseConnectionString(value: string, secretKeys: SecureKeys, config: SecureConfig): [string, string | SecureString][] {\n return value\n .split(';')\n .filter(Boolean)\n .map((pair) => {\n const [key, value] = pair.split('=');\n const v = value ?? '';\n const val = secretKeys.includes(key.toLocaleLowerCase()) ? SecureString.from(v, config) : v;\n return [key, val];\n });\n }\n\n static factory(config: SecureConfig): (value: string) => SecureConnectionString {\n return (value: string) => SecureConnectionString.from(value, config);\n }\n\n public static from<T extends string | null | undefined>(value: T, config: SecureConfig): T extends string ? SecureConnectionString : T {\n if (value === null) {\n return null as T extends string ? SecureConnectionString : T;\n }\n if (value === undefined) {\n return undefined as T extends string ? SecureConnectionString : T;\n }\n return new SecureConnectionString(value, config) as T extends string ? SecureConnectionString : T;\n }\n\n public override toString(): string {\n return this.#data.map(([key, value]) => `${key}=${value}`).join(';');\n }\n\n public override toJSON(): object {\n return Object.fromEntries(this.#data);\n }\n\n public override [util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string {\n if (depth < 0) {\n return '[SecureConnectionString]';\n }\n const newOptions = Object.assign({}, options, {\n depth: options.depth == null ? null : options.depth - 1,\n });\n return inspect(this.toJSON(), newOptions);\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{SecureString as r}from"./chunk-JAXX5FG7.js";import{ISecureURL as t}from"./chunk-XICVVAG4.js";import{__name as e}from"./chunk-7QVYU63E.js";import s from"node:util";var o=class o extends t{static{e(this,"SecureURL")}#r;#t;get secretValue(){return new URL(this.#r.getValue())}constructor(t,e){super(),this.#r=e.encryptionProvider.encrypt(t.href),this.#t=r.from(t.password||null,e)}static factory(r){return t=>o.from(t,r)}static from(r,t){return null===r?null:void 0!==r?new o(r,t):void 0}toString(){const r=this.secretValue,t=new URL(r.href);return null!==this.#t&&(t.password=this.#t.toString()),t.href}toJSON(){const r=this.secretValue,t=new URL(r.href);t.password="";const e=new URLSearchParams(t.searchParams);let s;t.search="",null!==this.#t&&(s=this.#t.toString());const o={href:t.href};return void 0!==s&&(o.password=s),e.size>0&&(o.searchParams=Object.fromEntries(e)),o}[s.inspect.custom](r,t,e){if(r<0)return"[SecureURL]";const s=Object.assign({},t,{depth:null==t.depth?null:t.depth-1});return e(this.toJSON(),s)}};export{o as SecureURL};//# sourceMappingURL=chunk-TGJY6ZQ7.js.map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AA,OAAO,OAAA,CAAQ,IAAA,CAAK,MAAA,EAAO,EAAG,UAAU,CAAA;AAAA,EAC1C;AACF","file":"chunk-TGJY6ZQ7.js","sourcesContent":["import util, { type InspectOptions } from 'node:util';\nimport { ISecureURL } from './interfaces';\nimport { SecureString } from './SecureString';\nimport type { IEncryptedValue, InspectFunction, SecureConfig } from './types';\n\ntype UrlObject = {\n href: string;\n password?: string;\n searchParams?: Record<string, string>;\n};\n\nexport class SecureURL extends ISecureURL {\n readonly #encryptedValue: IEncryptedValue;\n readonly #password: SecureString | null;\n\n public get secretValue(): URL {\n return new URL(this.#encryptedValue.getValue());\n }\n\n private constructor(value: URL, config: SecureConfig) {\n super();\n this.#encryptedValue = config.encryptionProvider.encrypt(value.href);\n this.#password = SecureString.from(value.password || null, config);\n }\n\n static factory(config: SecureConfig): (value: URL) => ISecureURL {\n return (value: URL) => SecureURL.from(value, config);\n }\n\n public static from<T extends URL | null | undefined>(value: T, config: SecureConfig): T extends URL ? SecureURL : T {\n if (value === null) {\n return null as T extends URL ? SecureURL : T;\n }\n if (value === undefined) {\n return undefined as T extends URL ? SecureURL : T;\n }\n return new SecureURL(value, config) as T extends URL ? SecureURL : T;\n }\n\n override toString(): string {\n const originalUrl = this.secretValue;\n const newUrl = new URL(originalUrl.href);\n if (this.#password !== null) {\n newUrl.password = this.#password.toString();\n }\n return newUrl.href;\n }\n\n override toJSON(): UrlObject {\n const originalUrl = this.secretValue;\n const newUrl = new URL(originalUrl.href);\n newUrl.password = '';\n\n const searchParams = new URLSearchParams(newUrl.searchParams);\n newUrl.search = '';\n\n let password: string | undefined;\n if (this.#password !== null) {\n password = this.#password.toString();\n }\n\n const result: UrlObject = {\n href: newUrl.href,\n };\n if (password !== undefined) {\n result.password = password;\n }\n if (searchParams.size > 0) {\n result.searchParams = Object.fromEntries(searchParams);\n }\n return result;\n }\n override [util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string {\n if (depth < 0) {\n return '[SecureURL]';\n }\n const newOptions = Object.assign({}, options, {\n depth: options.depth == null ? null : options.depth - 1,\n });\n return inspect(this.toJSON(), newOptions);\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{__name as t}from"./chunk-7QVYU63E.js";var s=class{static{t(this,"ISecureString")}},c=class{static{t(this,"ISecureConnectionString")}},i=class{static{t(this,"ISecureURL")}},r=class{static{t(this,"ISecureFactory")}};export{c as ISecureConnectionString,r as ISecureFactory,s as ISecureString,i as ISecureURL};//# sourceMappingURL=chunk-XICVVAG4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/interfaces.ts"],"names":[],"mappings":";AAGO,IAAe,gBAAf,MAAmD;AAAA,EAH1D;AAG0D,IAAA,MAAA,CAAA,IAAA,EAAA,eAAA,CAAA;AAAA;AAK1D;AAEO,IAAe,0BAAf,MAA6D;AAAA,EAVpE;AAUoE,IAAA,MAAA,CAAA,IAAA,EAAA,yBAAA,CAAA;AAAA;AAKpE;AAEO,IAAe,aAAf,MAAgD;AAAA,EAjBvD;AAiBuD,IAAA,MAAA,CAAA,IAAA,EAAA,YAAA,CAAA;AAAA;AAKvD;AAEO,IAAe,iBAAf,MAA8B;AAAA,EAxBrC;AAwBqC,IAAA,MAAA,CAAA,IAAA,EAAA,gBAAA,CAAA;AAAA;AAIrC","file":"chunk-XICVVAG4.js","sourcesContent":["import util, { type InspectOptions } from 'node:util';\nimport type { BaseObject, InspectFunction } from './types';\n\nexport abstract class ISecureString implements BaseObject {\n public abstract toString(): string;\n public abstract toJSON(): string | object;\n public abstract [util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string;\n public abstract get secretValue(): string;\n}\n\nexport abstract class ISecureConnectionString implements BaseObject {\n public abstract toString(): string;\n public abstract toJSON(): string | object;\n public abstract [util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string;\n public abstract get secretValue(): string;\n}\n\nexport abstract class ISecureURL implements BaseObject {\n public abstract toString(): string;\n public abstract toJSON(): object;\n public abstract [util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string;\n public abstract get secretValue(): URL;\n}\n\nexport abstract class ISecureFactory {\n public abstract string(value: string): ISecureString;\n public abstract connectionString(value: string, secretKeys?: readonly string[]): ISecureConnectionString;\n public abstract url(value: URL): ISecureURL;\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ISecureFactory } from './interfaces.js';
|
|
2
|
+
import { IEncryptionProvider, SecureConfig } from './types.js';
|
|
3
|
+
import 'node:util';
|
|
4
|
+
|
|
5
|
+
declare const defaultEncryptionProvider: IEncryptionProvider;
|
|
6
|
+
declare const createFactory: (options?: Partial<SecureConfig>) => ISecureFactory;
|
|
7
|
+
|
|
8
|
+
export { createFactory, defaultEncryptionProvider };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{createFactory,defaultEncryptionProvider}from"./chunk-NWPDBO55.js";import"./chunk-CGPJ25IS.js";import"./chunk-S3UXVGVK.js";import"./chunk-TGJY6ZQ7.js";import"./chunk-JAXX5FG7.js";import"./chunk-XICVVAG4.js";import"./chunk-FUGQ3OFQ.js";import"./chunk-GJXVQ2LL.js";import"./chunk-7QVYU63E.js";//# sourceMappingURL=createFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"createFactory.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{defaultSecureKeys}from"./chunk-FUGQ3OFQ.js";import"./chunk-7QVYU63E.js";//# sourceMappingURL=defaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"defaults.js"}
|
package/dist/esm/hash.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{hash}from"./chunk-GJXVQ2LL.js";import"./chunk-7QVYU63E.js";//# sourceMappingURL=hash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"hash.js"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { createFactory } from './createFactory.js';
|
|
2
|
+
export { defaultSecureKeys } from './defaults.js';
|
|
3
|
+
export { EncryptedValue } from './EncryptedValue.js';
|
|
4
|
+
export { ISecureConnectionString, ISecureString, ISecureURL } from './interfaces.js';
|
|
5
|
+
export { SecureConfig } from './types.js';
|
|
6
|
+
import 'node:util';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{createFactory}from"./chunk-NWPDBO55.js";export{EncryptedValue}from"./chunk-CGPJ25IS.js";import"./chunk-S3UXVGVK.js";import"./chunk-TGJY6ZQ7.js";import"./chunk-JAXX5FG7.js";export{ISecureConnectionString,ISecureString,ISecureURL}from"./chunk-XICVVAG4.js";export{defaultSecureKeys}from"./chunk-FUGQ3OFQ.js";import"./chunk-GJXVQ2LL.js";import"./chunk-7QVYU63E.js";//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import util, { InspectOptions } from 'node:util';
|
|
2
|
+
import { BaseObject, InspectFunction } from './types.js';
|
|
3
|
+
|
|
4
|
+
declare abstract class ISecureString implements BaseObject {
|
|
5
|
+
abstract toString(): string;
|
|
6
|
+
abstract toJSON(): string | object;
|
|
7
|
+
abstract [util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string;
|
|
8
|
+
abstract get secretValue(): string;
|
|
9
|
+
}
|
|
10
|
+
declare abstract class ISecureConnectionString implements BaseObject {
|
|
11
|
+
abstract toString(): string;
|
|
12
|
+
abstract toJSON(): string | object;
|
|
13
|
+
abstract [util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string;
|
|
14
|
+
abstract get secretValue(): string;
|
|
15
|
+
}
|
|
16
|
+
declare abstract class ISecureURL implements BaseObject {
|
|
17
|
+
abstract toString(): string;
|
|
18
|
+
abstract toJSON(): object;
|
|
19
|
+
abstract [util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string;
|
|
20
|
+
abstract get secretValue(): URL;
|
|
21
|
+
}
|
|
22
|
+
declare abstract class ISecureFactory {
|
|
23
|
+
abstract string(value: string): ISecureString;
|
|
24
|
+
abstract connectionString(value: string, secretKeys?: readonly string[]): ISecureConnectionString;
|
|
25
|
+
abstract url(value: URL): ISecureURL;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { ISecureConnectionString, ISecureFactory, ISecureString, ISecureURL };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{ISecureConnectionString,ISecureFactory,ISecureString,ISecureURL}from"./chunk-XICVVAG4.js";import"./chunk-7QVYU63E.js";//# sourceMappingURL=interfaces.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"interfaces.js"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import util, { InspectOptions } from 'node:util';
|
|
2
|
+
|
|
3
|
+
type InspectFunction = typeof util.inspect;
|
|
4
|
+
declare abstract class BaseObject {
|
|
5
|
+
abstract toString(): string;
|
|
6
|
+
abstract toJSON(): string | object;
|
|
7
|
+
abstract [util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string;
|
|
8
|
+
}
|
|
9
|
+
type SecureKeys = readonly string[];
|
|
10
|
+
interface IEncryptedValue {
|
|
11
|
+
getValue(): string;
|
|
12
|
+
toString(): string;
|
|
13
|
+
toJSON(): object;
|
|
14
|
+
}
|
|
15
|
+
interface IEncryptionProvider {
|
|
16
|
+
encrypt(value: string): IEncryptedValue;
|
|
17
|
+
}
|
|
18
|
+
interface SecureConfig {
|
|
19
|
+
secret: string | null;
|
|
20
|
+
encryptionProvider: IEncryptionProvider;
|
|
21
|
+
secretKeys: SecureKeys;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { BaseObject, type IEncryptedValue, type IEncryptionProvider, type InspectFunction, type SecureConfig, type SecureKeys };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{__name as s}from"./chunk-7QVYU63E.js";var t=class{static{s(this,"BaseObject")}};export{t as BaseObject};//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/types.ts"],"names":[],"mappings":";AAIO,IAAe,aAAf,MAA0B;AAAA,EAJjC;AAIiC,IAAA,MAAA,CAAA,IAAA,EAAA,YAAA,CAAA;AAAA;AAIjC","file":"types.js","sourcesContent":["import util, { type InspectOptions } from 'node:util';\n\nexport type InspectFunction = typeof util.inspect;\n\nexport abstract class BaseObject {\n public abstract toString(): string;\n public abstract toJSON(): string | object;\n public abstract [util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string;\n}\n\nexport type SecureKeys = readonly string[];\n\nexport interface IEncryptedValue {\n getValue(): string;\n toString(): string;\n toJSON(): object;\n}\n\nexport interface IEncryptionProvider {\n encrypt(value: string): IEncryptedValue;\n}\n\nexport interface SecureConfig {\n secret: string | null;\n encryptionProvider: IEncryptionProvider;\n secretKeys: SecureKeys;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shellicar/core-config",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.1.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "Stephen Hellicar",
|
|
@@ -28,18 +28,23 @@
|
|
|
28
28
|
},
|
|
29
29
|
"exports": {
|
|
30
30
|
".": {
|
|
31
|
-
"import":
|
|
32
|
-
|
|
31
|
+
"import": {
|
|
32
|
+
"types": "./dist/esm/index.d.ts",
|
|
33
|
+
"default": "./dist/esm/index.js"
|
|
34
|
+
},
|
|
35
|
+
"require": {
|
|
36
|
+
"types": "./dist/cjs/index.d.cts",
|
|
37
|
+
"default": "./dist/cjs/index.cjs"
|
|
38
|
+
}
|
|
33
39
|
}
|
|
34
40
|
},
|
|
35
|
-
"main": "dist/index.cjs",
|
|
36
|
-
"module": "dist/index.js",
|
|
37
|
-
"types": "dist/index.d.
|
|
41
|
+
"main": "dist/cjs/index.cjs",
|
|
42
|
+
"module": "dist/esm/index.js",
|
|
43
|
+
"types": "dist/esm/index.d.ts",
|
|
38
44
|
"typesVersions": {
|
|
39
45
|
"*": {
|
|
40
|
-
"
|
|
41
|
-
"./dist
|
|
42
|
-
"./*"
|
|
46
|
+
"index": [
|
|
47
|
+
"./dist/esm/index.d.ts"
|
|
43
48
|
]
|
|
44
49
|
}
|
|
45
50
|
},
|
|
@@ -48,12 +53,13 @@
|
|
|
48
53
|
"*.md"
|
|
49
54
|
],
|
|
50
55
|
"devDependencies": {
|
|
51
|
-
"@
|
|
52
|
-
"@
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
56
|
+
"@shellicar/build-clean": "1.0.0-preview.5",
|
|
57
|
+
"@tsconfig/node20": "^20.1.6",
|
|
58
|
+
"@types/node": "^24.3.0",
|
|
59
|
+
"terser": "^5.43.1",
|
|
60
|
+
"tsup": "^8.5.0",
|
|
61
|
+
"typescript": "^5.9.2",
|
|
62
|
+
"vitest": "^3.2.4"
|
|
57
63
|
},
|
|
58
64
|
"scripts": {
|
|
59
65
|
"build": "tsup-node",
|
package/dist/index.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var e=require("crypto");function t(e){return e&&e.__esModule?e:{default:e}}var r=t(require("util")),s=Object.defineProperty,n=(e,t)=>s(e,"name",{value:t,configurable:!0}),a=class{static{n(this,"EncryptedValue")}encryptedData;iv;authTag;key;constructor(t){this.key=e.randomBytes(32),this.iv=e.randomBytes(16);const r=e.createCipheriv("aes-256-gcm",this.key,this.iv),s=[];s.push(r.update(t,"utf8")),s.push(r.final()),this.encryptedData=Buffer.concat(s),this.authTag=r.getAuthTag()}getValue(){const t=e.createDecipheriv("aes-256-gcm",this.key,this.iv);t.setAuthTag(this.authTag);try{const e=[];return e.push(t.update(this.encryptedData)),e.push(t.final()),Buffer.concat(e).toString("utf8")}catch(e){throw new Error("Failed to decrypt value: Invalid key or corrupted data")}}toString(){return"[EncryptedValue]"}toJSON(){return{type:"EncryptedValue",encrypted:!0}}},c={sha256:n((()=>({hash:n((t=>e.createHash("sha256").update(t).digest("hex")),"hash"),prefix:"sha256"})),"sha256"),hs256:n((t=>({hash:n((r=>e.createHmac("sha256",t).update(r).digest("hex")),"hash"),prefix:"hs256"})),"hs256")},i=n((e=>null==e?c.sha256():c.hs256(e)),"getAlgorithm"),o=n(((e,t)=>{const r=i(t),s=r.hash(e);return`${r.prefix}:${s}`}),"hash"),u=class{static{n(this,"ISecureString")}},h=class{static{n(this,"ISecureConnectionString")}},l=class{static{n(this,"ISecureURL")}},p=class e extends u{static{n(this,"SecureString")}#e;#t;get secretValue(){return this.#e.getValue()}constructor(e,t){super(),this.#e=t.encryptionProvider.encrypt(e),this.#t=o(e,t.secret)}static factory(t){return r=>e.from(r,t)}static from(t,r){return null===t?null:void 0!==t?new e(t,r):void 0}toString(){return this.#t}toJSON(){return this.toString()}[r.default.inspect.custom](e,t,r){if(e<0)return"[SecureString]";const s=Object.assign({},t,{depth:null==t.depth?null:t.depth-1});return r(this.toJSON(),s)}},d=class e extends h{static{n(this,"SecureConnectionString")}#e;#r;get secretValue(){return this.#e.getValue()}constructor(e,t){super(),this.#e=t.encryptionProvider.encrypt(e),this.#r=this.parseConnectionString(e,t.secretKeys.map((e=>e.toLocaleLowerCase())),t)}parseConnectionString(e,t,r){return e.split(";").filter(Boolean).map((e=>{const[s,n]=e.split("="),a=n??"",c=t.includes(s.toLocaleLowerCase())?p.from(a,r):a;return[s,c]}))}static factory(t){return r=>e.from(r,t)}static from(t,r){return null===t?null:void 0!==t?new e(t,r):void 0}toString(){return this.#r.map((([e,t])=>`${e}=${t}`)).join(";")}toJSON(){return Object.fromEntries(this.#r)}[r.default.inspect.custom](e,t,r){if(e<0)return"[SecureConnectionString]";const s=Object.assign({},t,{depth:null==t.depth?null:t.depth-1});return r(this.toJSON(),s)}},y=class e extends l{static{n(this,"SecureURL")}#e;#s;get secretValue(){return new URL(this.#e.getValue())}constructor(e,t){super(),this.#e=t.encryptionProvider.encrypt(e.href),this.#s=p.from(e.password||null,t)}static factory(t){return r=>e.from(r,t)}static from(t,r){return null===t?null:void 0!==t?new e(t,r):void 0}toString(){const e=this.secretValue,t=new URL(e.href);return null!==this.#s&&(t.password=this.#s.toString()),t.href}toJSON(){const e=this.secretValue,t=new URL(e.href);t.password="";const r=new URLSearchParams(t.searchParams);let s;t.search="",null!==this.#s&&(s=this.#s.toString());const n={href:t.href};return void 0!==s&&(n.password=s),r.size>0&&(n.searchParams=Object.fromEntries(r)),n}[r.default.inspect.custom](e,t,r){if(e<0)return"[SecureURL]";const s=Object.assign({},t,{depth:null==t.depth?null:t.depth-1});return r(this.toJSON(),s)}},f=["AccessKey","SharedAccessKey","Password","AccountKey","Secret","SecretKey","ApiKey","Token","Key","MasterKey","PrimaryKey","SecondaryKey"],S={encrypt:n((e=>new a(e)),"encrypt")},g=n((e=>{const t={secret:e?.secret??null,encryptionProvider:e?.encryptionProvider??S,secretKeys:e?.secretKeys??f};return{string:p.factory(t),connectionString:d.factory(t),url:y.factory(t)}}),"createFactory");exports.EncryptedValue=a,exports.ISecureConnectionString=h,exports.ISecureString=u,exports.ISecureURL=l,exports.createFactory=g,exports.defaultSecureKeys=f;//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/EncryptedValue.ts","../src/hash.ts","../src/interfaces.ts","../src/SecureString.ts","../src/SecureConnectionString.ts","../src/SecureURL.ts","../src/defaults.ts","../src/createFactory.ts"],"names":["randomBytes","createCipheriv","createDecipheriv","createHash","createHmac","hash","util","value"],"mappings":";;AAEO,IAAM,iBAAN,MAAq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O,CAAA,IAAI,OAAS,EAAA;AAAA,MAC5C,OAAO,OAAQ,CAAA,KAAA,IAAS,IAAO,GAAA,IAAA,GAAO,QAAQ,KAAQ,GAAA;AAAA,KACvD,CAAA;AACD,IAAA,OAAO,OAAQ,CAAA,IAAA,CAAK,MAAO,EAAA,EAAG,UAAU,CAAA;AAAA;AAE5C,CAAA;;;AC/EO,IAAM,iBAAoB,GAAA,CAAC,WAAa,EAAA,iBAAA,EAAmB,UAAY,EAAA,YAAA,EAAc,QAAU,EAAA,WAAA,EAAa,QAAU,EAAA,OAAA,EAAS,KAAO,EAAA,WAAA,EAAa,cAAc,cAAc;;;ACM/K,IAAM,yBAAiD,GAAA;AAAA,EAC5D,yBAAU,MAAA,CAAA,CAAA,KAAA,KAAkB,IAAI,cAAA,CAAe,KAAK,CAA3C,EAAA,SAAA;AACX,CAAA;AAEa,IAAA,aAAA,2BAAiB,OAAoD,KAAA;AAChF,EAAA,MAAM,MAAuB,GAAA;AAAA,IAC3B,MAAA,EAAQ,SAAS,MAAU,IAAA,IAAA;AAAA,IAC3B,kBAAA,EAAoB,SAAS,kBAAsB,IAAA,yBAAA;AAAA,IACnD,UAAA,EAAY,SAAS,UAAc,IAAA;AAAA,GACrC;AAEA,EAAO,OAAA;AAAA,IACL,MAAA,EAAQ,YAAa,CAAA,OAAA,CAAQ,MAAM,CAAA;AAAA,IACnC,gBAAA,EAAkB,sBAAuB,CAAA,OAAA,CAAQ,MAAM,CAAA;AAAA,IACvD,GAAA,EAAK,SAAU,CAAA,OAAA,CAAQ,MAAM;AAAA,GAC/B;AACF,CAZ6B,EAAA,eAAA","file":"index.cjs","sourcesContent":["import { createCipheriv, createDecipheriv, randomBytes } from 'node:crypto';\n\nexport class EncryptedValue {\n private readonly encryptedData: Buffer;\n private readonly iv: Buffer;\n private readonly authTag: Buffer;\n private readonly key: Buffer;\n\n public constructor(value: string) {\n this.key = randomBytes(32);\n this.iv = randomBytes(16);\n\n const cipher = createCipheriv('aes-256-gcm', this.key, this.iv);\n\n const encryptedChunks: Buffer[] = [];\n encryptedChunks.push(cipher.update(value, 'utf8'));\n encryptedChunks.push(cipher.final());\n\n this.encryptedData = Buffer.concat(encryptedChunks);\n this.authTag = cipher.getAuthTag();\n }\n\n public getValue(): string {\n const decipher = createDecipheriv('aes-256-gcm', this.key, this.iv);\n decipher.setAuthTag(this.authTag);\n\n try {\n const decryptedChunks: Buffer[] = [];\n decryptedChunks.push(decipher.update(this.encryptedData));\n decryptedChunks.push(decipher.final());\n\n return Buffer.concat(decryptedChunks).toString('utf8');\n } catch (_) {\n // Hide internal error details\n throw new Error('Failed to decrypt value: Invalid key or corrupted data');\n }\n }\n\n public toString(): string {\n return '[EncryptedValue]';\n }\n\n public toJSON(): object {\n return { type: 'EncryptedValue', encrypted: true };\n }\n}\n","import { createHash, createHmac } from 'node:crypto';\n\ntype HashAlgorithm = {\n hash: (x: string) => string;\n prefix: string;\n};\n\nconst algorithms = {\n sha256: () => ({\n hash: (x: string) => createHash('sha256').update(x).digest('hex'),\n prefix: 'sha256',\n }),\n hs256: (secret: string) => ({\n hash: (x: string) => createHmac('sha256', secret).update(x).digest('hex'),\n prefix: 'hs256',\n }),\n} as const;\n\nconst getAlgorithm = (secret: string | null): HashAlgorithm => {\n return secret == null ? algorithms.sha256() : algorithms.hs256(secret);\n};\n\nexport const hash = (input: string, secret: string | null) => {\n const alg = getAlgorithm(secret);\n const hash = alg.hash(input);\n return `${alg.prefix}:${hash}`;\n};\n","import util, { type InspectOptions } from 'node:util';\nimport type { BaseObject, InspectFunction } from './types';\n\nexport abstract class ISecureString implements BaseObject {\n public abstract toString(): string;\n public abstract toJSON(): string | object;\n public abstract [util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string;\n public abstract get secretValue(): string;\n}\n\nexport abstract class ISecureConnectionString implements BaseObject {\n public abstract toString(): string;\n public abstract toJSON(): string | object;\n public abstract [util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string;\n public abstract get secretValue(): string;\n}\n\nexport abstract class ISecureURL implements BaseObject {\n public abstract toString(): string;\n public abstract toJSON(): object;\n public abstract [util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string;\n public abstract get secretValue(): URL;\n}\n\nexport abstract class ISecureFactory {\n public abstract string(value: string): ISecureString;\n public abstract connectionString(value: string, secretKeys?: readonly string[]): ISecureConnectionString;\n public abstract url(value: URL): ISecureURL;\n}\n","import util, { type InspectOptions } from 'node:util';\nimport { hash } from './hash';\nimport { ISecureString } from './interfaces';\nimport type { IEncryptedValue, InspectFunction, SecureConfig } from './types';\n\nexport class SecureString extends ISecureString {\n readonly #encryptedValue: IEncryptedValue;\n readonly #hash: string;\n\n public get secretValue(): string {\n return this.#encryptedValue.getValue();\n }\n\n private constructor(value: string, config: SecureConfig) {\n super();\n this.#encryptedValue = config.encryptionProvider.encrypt(value);\n this.#hash = hash(value, config.secret);\n }\n\n static factory(config: SecureConfig): (value: string) => SecureString {\n return (value: string) => SecureString.from(value, config);\n }\n\n public static from<T extends string | null | undefined>(value: T, config: SecureConfig): T extends string ? SecureString : T {\n if (value === null) {\n return null as T extends string ? SecureString : T;\n }\n if (value === undefined) {\n return undefined as T extends string ? SecureString : T;\n }\n return new SecureString(value, config) as T extends string ? SecureString : T;\n }\n\n public override toString() {\n return this.#hash;\n }\n public override toJSON() {\n return this.toString();\n }\n override [util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string {\n if (depth < 0) {\n return '[SecureString]';\n }\n const newOptions = Object.assign({}, options, {\n depth: options.depth == null ? null : options.depth - 1,\n });\n return inspect(this.toJSON(), newOptions);\n }\n}\n","import util, { type InspectOptions } from 'node:util';\nimport { SecureString } from './SecureString';\nimport { ISecureConnectionString } from './interfaces';\nimport type { IEncryptedValue, InspectFunction, SecureConfig, SecureKeys } from './types';\n\nexport class SecureConnectionString extends ISecureConnectionString {\n readonly #encryptedValue: IEncryptedValue;\n readonly #data: [string, string | SecureString][];\n\n public get secretValue(): string {\n return this.#encryptedValue.getValue();\n }\n\n private constructor(value: string, config: SecureConfig) {\n super();\n this.#encryptedValue = config.encryptionProvider.encrypt(value);\n this.#data = this.parseConnectionString(\n value,\n config.secretKeys.map((x) => x.toLocaleLowerCase()),\n config,\n );\n }\n\n private parseConnectionString(value: string, secretKeys: SecureKeys, config: SecureConfig): [string, string | SecureString][] {\n return value\n .split(';')\n .filter(Boolean)\n .map((pair) => {\n const [key, value] = pair.split('=');\n const v = value ?? '';\n const val = secretKeys.includes(key.toLocaleLowerCase()) ? SecureString.from(v, config) : v;\n return [key, val];\n });\n }\n\n static factory(config: SecureConfig): (value: string) => SecureConnectionString {\n return (value: string) => SecureConnectionString.from(value, config);\n }\n\n public static from<T extends string | null | undefined>(value: T, config: SecureConfig): T extends string ? SecureConnectionString : T {\n if (value === null) {\n return null as T extends string ? SecureConnectionString : T;\n }\n if (value === undefined) {\n return undefined as T extends string ? SecureConnectionString : T;\n }\n return new SecureConnectionString(value, config) as T extends string ? SecureConnectionString : T;\n }\n\n public override toString(): string {\n return this.#data.map(([key, value]) => `${key}=${value}`).join(';');\n }\n\n public override toJSON(): object {\n return Object.fromEntries(this.#data);\n }\n\n public override [util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string {\n if (depth < 0) {\n return '[SecureConnectionString]';\n }\n const newOptions = Object.assign({}, options, {\n depth: options.depth == null ? null : options.depth - 1,\n });\n return inspect(this.toJSON(), newOptions);\n }\n}\n","import util, { type InspectOptions } from 'node:util';\nimport { SecureString } from './SecureString';\nimport { ISecureURL } from './interfaces';\nimport type { IEncryptedValue, InspectFunction, SecureConfig } from './types';\n\ntype UrlObject = {\n href: string;\n password?: string;\n searchParams?: Record<string, string>;\n};\n\nexport class SecureURL extends ISecureURL {\n readonly #encryptedValue: IEncryptedValue;\n readonly #password: SecureString | null;\n\n public get secretValue(): URL {\n return new URL(this.#encryptedValue.getValue());\n }\n\n private constructor(value: URL, config: SecureConfig) {\n super();\n this.#encryptedValue = config.encryptionProvider.encrypt(value.href);\n this.#password = SecureString.from(value.password || null, config);\n }\n\n static factory(config: SecureConfig): (value: URL) => ISecureURL {\n return (value: URL) => SecureURL.from(value, config);\n }\n\n public static from<T extends URL | null | undefined>(value: T, config: SecureConfig): T extends URL ? SecureURL : T {\n if (value === null) {\n return null as T extends URL ? SecureURL : T;\n }\n if (value === undefined) {\n return undefined as T extends URL ? SecureURL : T;\n }\n return new SecureURL(value, config) as T extends URL ? SecureURL : T;\n }\n\n override toString(): string {\n const originalUrl = this.secretValue;\n const newUrl = new URL(originalUrl.href);\n if (this.#password !== null) {\n newUrl.password = this.#password.toString();\n }\n return newUrl.href;\n }\n\n override toJSON(): UrlObject {\n const originalUrl = this.secretValue;\n const newUrl = new URL(originalUrl.href);\n newUrl.password = '';\n\n const searchParams = new URLSearchParams(newUrl.searchParams);\n newUrl.search = '';\n\n let password: string | undefined;\n if (this.#password !== null) {\n password = this.#password.toString();\n }\n\n const result: UrlObject = {\n href: newUrl.href,\n };\n if (password !== undefined) {\n result.password = password;\n }\n if (searchParams.size > 0) {\n result.searchParams = Object.fromEntries(searchParams);\n }\n return result;\n }\n override [util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string {\n if (depth < 0) {\n return '[SecureURL]';\n }\n const newOptions = Object.assign({}, options, {\n depth: options.depth == null ? null : options.depth - 1,\n });\n return inspect(this.toJSON(), newOptions);\n }\n}\n","import type { SecureKeys } from './types';\n\nexport const defaultSecureKeys = ['AccessKey', 'SharedAccessKey', 'Password', 'AccountKey', 'Secret', 'SecretKey', 'ApiKey', 'Token', 'Key', 'MasterKey', 'PrimaryKey', 'SecondaryKey'] as const satisfies SecureKeys;\n","import { EncryptedValue } from './EncryptedValue';\nimport { SecureConnectionString } from './SecureConnectionString';\nimport { SecureString } from './SecureString';\nimport { SecureURL } from './SecureURL';\nimport { defaultSecureKeys } from './defaults';\nimport type { ISecureFactory } from './interfaces';\nimport type { IEncryptionProvider, SecureConfig } from './types';\n\nexport const defaultEncryptionProvider: IEncryptionProvider = {\n encrypt: (value: string) => new EncryptedValue(value),\n};\n\nexport const createFactory = (options?: Partial<SecureConfig>): ISecureFactory => {\n const config: SecureConfig = {\n secret: options?.secret ?? null,\n encryptionProvider: options?.encryptionProvider ?? defaultEncryptionProvider,\n secretKeys: options?.secretKeys ?? defaultSecureKeys,\n };\n\n return {\n string: SecureString.factory(config),\n connectionString: SecureConnectionString.factory(config),\n url: SecureURL.factory(config),\n };\n};\n"]}
|
package/dist/index.d.cts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import util, { InspectOptions } from 'node:util';
|
|
2
|
-
|
|
3
|
-
declare class EncryptedValue {
|
|
4
|
-
private readonly encryptedData;
|
|
5
|
-
private readonly iv;
|
|
6
|
-
private readonly authTag;
|
|
7
|
-
private readonly key;
|
|
8
|
-
constructor(value: string);
|
|
9
|
-
getValue(): string;
|
|
10
|
-
toString(): string;
|
|
11
|
-
toJSON(): object;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
type InspectFunction = typeof util.inspect;
|
|
15
|
-
declare abstract class BaseObject {
|
|
16
|
-
abstract toString(): string;
|
|
17
|
-
abstract toJSON(): string | object;
|
|
18
|
-
abstract [util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string;
|
|
19
|
-
}
|
|
20
|
-
type SecureKeys = readonly string[];
|
|
21
|
-
interface IEncryptedValue {
|
|
22
|
-
getValue(): string;
|
|
23
|
-
toString(): string;
|
|
24
|
-
toJSON(): object;
|
|
25
|
-
}
|
|
26
|
-
interface IEncryptionProvider {
|
|
27
|
-
encrypt(value: string): IEncryptedValue;
|
|
28
|
-
}
|
|
29
|
-
interface SecureConfig {
|
|
30
|
-
secret: string | null;
|
|
31
|
-
encryptionProvider: IEncryptionProvider;
|
|
32
|
-
secretKeys: SecureKeys;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
declare abstract class ISecureString implements BaseObject {
|
|
36
|
-
abstract toString(): string;
|
|
37
|
-
abstract toJSON(): string | object;
|
|
38
|
-
abstract [util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string;
|
|
39
|
-
abstract get secretValue(): string;
|
|
40
|
-
}
|
|
41
|
-
declare abstract class ISecureConnectionString implements BaseObject {
|
|
42
|
-
abstract toString(): string;
|
|
43
|
-
abstract toJSON(): string | object;
|
|
44
|
-
abstract [util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string;
|
|
45
|
-
abstract get secretValue(): string;
|
|
46
|
-
}
|
|
47
|
-
declare abstract class ISecureURL implements BaseObject {
|
|
48
|
-
abstract toString(): string;
|
|
49
|
-
abstract toJSON(): object;
|
|
50
|
-
abstract [util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string;
|
|
51
|
-
abstract get secretValue(): URL;
|
|
52
|
-
}
|
|
53
|
-
declare abstract class ISecureFactory {
|
|
54
|
-
abstract string(value: string): ISecureString;
|
|
55
|
-
abstract connectionString(value: string, secretKeys?: readonly string[]): ISecureConnectionString;
|
|
56
|
-
abstract url(value: URL): ISecureURL;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
declare const createFactory: (options?: Partial<SecureConfig>) => ISecureFactory;
|
|
60
|
-
|
|
61
|
-
declare const defaultSecureKeys: readonly ["AccessKey", "SharedAccessKey", "Password", "AccountKey", "Secret", "SecretKey", "ApiKey", "Token", "Key", "MasterKey", "PrimaryKey", "SecondaryKey"];
|
|
62
|
-
|
|
63
|
-
export { EncryptedValue, ISecureConnectionString, ISecureString, ISecureURL, createFactory, defaultSecureKeys };
|
package/dist/index.d.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import util, { InspectOptions } from 'node:util';
|
|
2
|
-
|
|
3
|
-
declare class EncryptedValue {
|
|
4
|
-
private readonly encryptedData;
|
|
5
|
-
private readonly iv;
|
|
6
|
-
private readonly authTag;
|
|
7
|
-
private readonly key;
|
|
8
|
-
constructor(value: string);
|
|
9
|
-
getValue(): string;
|
|
10
|
-
toString(): string;
|
|
11
|
-
toJSON(): object;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
type InspectFunction = typeof util.inspect;
|
|
15
|
-
declare abstract class BaseObject {
|
|
16
|
-
abstract toString(): string;
|
|
17
|
-
abstract toJSON(): string | object;
|
|
18
|
-
abstract [util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string;
|
|
19
|
-
}
|
|
20
|
-
type SecureKeys = readonly string[];
|
|
21
|
-
interface IEncryptedValue {
|
|
22
|
-
getValue(): string;
|
|
23
|
-
toString(): string;
|
|
24
|
-
toJSON(): object;
|
|
25
|
-
}
|
|
26
|
-
interface IEncryptionProvider {
|
|
27
|
-
encrypt(value: string): IEncryptedValue;
|
|
28
|
-
}
|
|
29
|
-
interface SecureConfig {
|
|
30
|
-
secret: string | null;
|
|
31
|
-
encryptionProvider: IEncryptionProvider;
|
|
32
|
-
secretKeys: SecureKeys;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
declare abstract class ISecureString implements BaseObject {
|
|
36
|
-
abstract toString(): string;
|
|
37
|
-
abstract toJSON(): string | object;
|
|
38
|
-
abstract [util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string;
|
|
39
|
-
abstract get secretValue(): string;
|
|
40
|
-
}
|
|
41
|
-
declare abstract class ISecureConnectionString implements BaseObject {
|
|
42
|
-
abstract toString(): string;
|
|
43
|
-
abstract toJSON(): string | object;
|
|
44
|
-
abstract [util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string;
|
|
45
|
-
abstract get secretValue(): string;
|
|
46
|
-
}
|
|
47
|
-
declare abstract class ISecureURL implements BaseObject {
|
|
48
|
-
abstract toString(): string;
|
|
49
|
-
abstract toJSON(): object;
|
|
50
|
-
abstract [util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string;
|
|
51
|
-
abstract get secretValue(): URL;
|
|
52
|
-
}
|
|
53
|
-
declare abstract class ISecureFactory {
|
|
54
|
-
abstract string(value: string): ISecureString;
|
|
55
|
-
abstract connectionString(value: string, secretKeys?: readonly string[]): ISecureConnectionString;
|
|
56
|
-
abstract url(value: URL): ISecureURL;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
declare const createFactory: (options?: Partial<SecureConfig>) => ISecureFactory;
|
|
60
|
-
|
|
61
|
-
declare const defaultSecureKeys: readonly ["AccessKey", "SharedAccessKey", "Password", "AccountKey", "Secret", "SecretKey", "ApiKey", "Token", "Key", "MasterKey", "PrimaryKey", "SecondaryKey"];
|
|
62
|
-
|
|
63
|
-
export { EncryptedValue, ISecureConnectionString, ISecureString, ISecureURL, createFactory, defaultSecureKeys };
|
package/dist/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{randomBytes as t,createCipheriv as e,createDecipheriv as r,createHash as s,createHmac as n}from"node:crypto";import a from"node:util";var c=Object.defineProperty,i=(t,e)=>c(t,"name",{value:e,configurable:!0}),o=class{static{i(this,"EncryptedValue")}encryptedData;iv;authTag;key;constructor(r){this.key=t(32),this.iv=t(16);const s=e("aes-256-gcm",this.key,this.iv),n=[];n.push(s.update(r,"utf8")),n.push(s.final()),this.encryptedData=Buffer.concat(n),this.authTag=s.getAuthTag()}getValue(){const t=r("aes-256-gcm",this.key,this.iv);t.setAuthTag(this.authTag);try{const e=[];return e.push(t.update(this.encryptedData)),e.push(t.final()),Buffer.concat(e).toString("utf8")}catch(t){throw new Error("Failed to decrypt value: Invalid key or corrupted data")}}toString(){return"[EncryptedValue]"}toJSON(){return{type:"EncryptedValue",encrypted:!0}}},u={sha256:i((()=>({hash:i((t=>s("sha256").update(t).digest("hex")),"hash"),prefix:"sha256"})),"sha256"),hs256:i((t=>({hash:i((e=>n("sha256",t).update(e).digest("hex")),"hash"),prefix:"hs256"})),"hs256")},h=i((t=>null==t?u.sha256():u.hs256(t)),"getAlgorithm"),l=i(((t,e)=>{const r=h(e),s=r.hash(t);return`${r.prefix}:${s}`}),"hash"),p=class{static{i(this,"ISecureString")}},d=class{static{i(this,"ISecureConnectionString")}},y=class{static{i(this,"ISecureURL")}},f=class t extends p{static{i(this,"SecureString")}#t;#e;get secretValue(){return this.#t.getValue()}constructor(t,e){super(),this.#t=e.encryptionProvider.encrypt(t),this.#e=l(t,e.secret)}static factory(e){return r=>t.from(r,e)}static from(e,r){return null===e?null:void 0!==e?new t(e,r):void 0}toString(){return this.#e}toJSON(){return this.toString()}[a.inspect.custom](t,e,r){if(t<0)return"[SecureString]";const s=Object.assign({},e,{depth:null==e.depth?null:e.depth-1});return r(this.toJSON(),s)}},g=class t extends d{static{i(this,"SecureConnectionString")}#t;#r;get secretValue(){return this.#t.getValue()}constructor(t,e){super(),this.#t=e.encryptionProvider.encrypt(t),this.#r=this.parseConnectionString(t,e.secretKeys.map((t=>t.toLocaleLowerCase())),e)}parseConnectionString(t,e,r){return t.split(";").filter(Boolean).map((t=>{const[s,n]=t.split("="),a=n??"",c=e.includes(s.toLocaleLowerCase())?f.from(a,r):a;return[s,c]}))}static factory(e){return r=>t.from(r,e)}static from(e,r){return null===e?null:void 0!==e?new t(e,r):void 0}toString(){return this.#r.map((([t,e])=>`${t}=${e}`)).join(";")}toJSON(){return Object.fromEntries(this.#r)}[a.inspect.custom](t,e,r){if(t<0)return"[SecureConnectionString]";const s=Object.assign({},e,{depth:null==e.depth?null:e.depth-1});return r(this.toJSON(),s)}},S=class t extends y{static{i(this,"SecureURL")}#t;#s;get secretValue(){return new URL(this.#t.getValue())}constructor(t,e){super(),this.#t=e.encryptionProvider.encrypt(t.href),this.#s=f.from(t.password||null,e)}static factory(e){return r=>t.from(r,e)}static from(e,r){return null===e?null:void 0!==e?new t(e,r):void 0}toString(){const t=this.secretValue,e=new URL(t.href);return null!==this.#s&&(e.password=this.#s.toString()),e.href}toJSON(){const t=this.secretValue,e=new URL(t.href);e.password="";const r=new URLSearchParams(e.searchParams);let s;e.search="",null!==this.#s&&(s=this.#s.toString());const n={href:e.href};return void 0!==s&&(n.password=s),r.size>0&&(n.searchParams=Object.fromEntries(r)),n}[a.inspect.custom](t,e,r){if(t<0)return"[SecureURL]";const s=Object.assign({},e,{depth:null==e.depth?null:e.depth-1});return r(this.toJSON(),s)}},m=["AccessKey","SharedAccessKey","Password","AccountKey","Secret","SecretKey","ApiKey","Token","Key","MasterKey","PrimaryKey","SecondaryKey"],w={encrypt:i((t=>new o(t)),"encrypt")},V=i((t=>{const e={secret:t?.secret??null,encryptionProvider:t?.encryptionProvider??w,secretKeys:t?.secretKeys??m};return{string:f.factory(e),connectionString:g.factory(e),url:S.factory(e)}}),"createFactory");export{o as EncryptedValue,d as ISecureConnectionString,p as ISecureString,y as ISecureURL,V as createFactory,m as defaultSecureKeys};//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/EncryptedValue.ts","../src/hash.ts","../src/interfaces.ts","../src/SecureString.ts","../src/SecureConnectionString.ts","../src/SecureURL.ts","../src/defaults.ts","../src/createFactory.ts"],"names":["hash","value","util"],"mappings":";;AAEO,IAAM,iBAAN,MAAqB;AAAA,EAF5B;AAE4B,IAAA,MAAA,CAAA,IAAA,EAAA,gBAAA,CAAA;AAAA;AAAA,EACT,aAAA;AAAA,EACA,EAAA;AAAA,EACA,OAAA;AAAA,EACA,GAAA;AAAA,EAEV,YAAY,KAAe,EAAA;AAChC,IAAK,IAAA,CAAA,GAAA,GAAM,YAAY,EAAE,CAAA;AACzB,IAAK,IAAA,CAAA,EAAA,GAAK,YAAY,EAAE,CAAA;AAExB,IAAA,MAAM,SAAS,cAAe,CAAA,aAAA,EAAe,IAAK,CAAA,GAAA,EAAK,KAAK,EAAE,CAAA;AAE9D,IAAA,MAAM,kBAA4B,EAAC;AACnC,IAAA,eAAA,CAAgB,IAAK,CAAA,MAAA,CAAO,MAAO,CAAA,KAAA,EAAO,MAAM,CAAC,CAAA;AACjD,IAAgB,eAAA,CAAA,IAAA,CAAK,MAAO,CAAA,KAAA,EAAO,CAAA;AAEnC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MAAM,MAAuB,GAAA;AAAA,IAC3B,MAAA,EAAQ,SAAS,MAAU,IAAA,IAAA;AAAA,IAC3B,kBAAA,EAAoB,SAAS,kBAAsB,IAAA,yBAAA;AAAA,IACnD,UAAA,EAAY,SAAS,UAAc,IAAA;AAAA,GACrC;AAEA,EAAO,OAAA;AAAA,IACL,MAAA,EAAQ,YAAa,CAAA,OAAA,CAAQ,MAAM,CAAA;AAAA,IACnC,gBAAA,EAAkB,sBAAuB,CAAA,OAAA,CAAQ,MAAM,CAAA;AAAA,IACvD,GAAA,EAAK,SAAU,CAAA,OAAA,CAAQ,MAAM;AAAA,GAC/B;AACF,CAZ6B,EAAA,eAAA","file":"index.js","sourcesContent":["import { createCipheriv, createDecipheriv, randomBytes } from 'node:crypto';\n\nexport class EncryptedValue {\n private readonly encryptedData: Buffer;\n private readonly iv: Buffer;\n private readonly authTag: Buffer;\n private readonly key: Buffer;\n\n public constructor(value: string) {\n this.key = randomBytes(32);\n this.iv = randomBytes(16);\n\n const cipher = createCipheriv('aes-256-gcm', this.key, this.iv);\n\n const encryptedChunks: Buffer[] = [];\n encryptedChunks.push(cipher.update(value, 'utf8'));\n encryptedChunks.push(cipher.final());\n\n this.encryptedData = Buffer.concat(encryptedChunks);\n this.authTag = cipher.getAuthTag();\n }\n\n public getValue(): string {\n const decipher = createDecipheriv('aes-256-gcm', this.key, this.iv);\n decipher.setAuthTag(this.authTag);\n\n try {\n const decryptedChunks: Buffer[] = [];\n decryptedChunks.push(decipher.update(this.encryptedData));\n decryptedChunks.push(decipher.final());\n\n return Buffer.concat(decryptedChunks).toString('utf8');\n } catch (_) {\n // Hide internal error details\n throw new Error('Failed to decrypt value: Invalid key or corrupted data');\n }\n }\n\n public toString(): string {\n return '[EncryptedValue]';\n }\n\n public toJSON(): object {\n return { type: 'EncryptedValue', encrypted: true };\n }\n}\n","import { createHash, createHmac } from 'node:crypto';\n\ntype HashAlgorithm = {\n hash: (x: string) => string;\n prefix: string;\n};\n\nconst algorithms = {\n sha256: () => ({\n hash: (x: string) => createHash('sha256').update(x).digest('hex'),\n prefix: 'sha256',\n }),\n hs256: (secret: string) => ({\n hash: (x: string) => createHmac('sha256', secret).update(x).digest('hex'),\n prefix: 'hs256',\n }),\n} as const;\n\nconst getAlgorithm = (secret: string | null): HashAlgorithm => {\n return secret == null ? algorithms.sha256() : algorithms.hs256(secret);\n};\n\nexport const hash = (input: string, secret: string | null) => {\n const alg = getAlgorithm(secret);\n const hash = alg.hash(input);\n return `${alg.prefix}:${hash}`;\n};\n","import util, { type InspectOptions } from 'node:util';\nimport type { BaseObject, InspectFunction } from './types';\n\nexport abstract class ISecureString implements BaseObject {\n public abstract toString(): string;\n public abstract toJSON(): string | object;\n public abstract [util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string;\n public abstract get secretValue(): string;\n}\n\nexport abstract class ISecureConnectionString implements BaseObject {\n public abstract toString(): string;\n public abstract toJSON(): string | object;\n public abstract [util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string;\n public abstract get secretValue(): string;\n}\n\nexport abstract class ISecureURL implements BaseObject {\n public abstract toString(): string;\n public abstract toJSON(): object;\n public abstract [util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string;\n public abstract get secretValue(): URL;\n}\n\nexport abstract class ISecureFactory {\n public abstract string(value: string): ISecureString;\n public abstract connectionString(value: string, secretKeys?: readonly string[]): ISecureConnectionString;\n public abstract url(value: URL): ISecureURL;\n}\n","import util, { type InspectOptions } from 'node:util';\nimport { hash } from './hash';\nimport { ISecureString } from './interfaces';\nimport type { IEncryptedValue, InspectFunction, SecureConfig } from './types';\n\nexport class SecureString extends ISecureString {\n readonly #encryptedValue: IEncryptedValue;\n readonly #hash: string;\n\n public get secretValue(): string {\n return this.#encryptedValue.getValue();\n }\n\n private constructor(value: string, config: SecureConfig) {\n super();\n this.#encryptedValue = config.encryptionProvider.encrypt(value);\n this.#hash = hash(value, config.secret);\n }\n\n static factory(config: SecureConfig): (value: string) => SecureString {\n return (value: string) => SecureString.from(value, config);\n }\n\n public static from<T extends string | null | undefined>(value: T, config: SecureConfig): T extends string ? SecureString : T {\n if (value === null) {\n return null as T extends string ? SecureString : T;\n }\n if (value === undefined) {\n return undefined as T extends string ? SecureString : T;\n }\n return new SecureString(value, config) as T extends string ? SecureString : T;\n }\n\n public override toString() {\n return this.#hash;\n }\n public override toJSON() {\n return this.toString();\n }\n override [util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string {\n if (depth < 0) {\n return '[SecureString]';\n }\n const newOptions = Object.assign({}, options, {\n depth: options.depth == null ? null : options.depth - 1,\n });\n return inspect(this.toJSON(), newOptions);\n }\n}\n","import util, { type InspectOptions } from 'node:util';\nimport { SecureString } from './SecureString';\nimport { ISecureConnectionString } from './interfaces';\nimport type { IEncryptedValue, InspectFunction, SecureConfig, SecureKeys } from './types';\n\nexport class SecureConnectionString extends ISecureConnectionString {\n readonly #encryptedValue: IEncryptedValue;\n readonly #data: [string, string | SecureString][];\n\n public get secretValue(): string {\n return this.#encryptedValue.getValue();\n }\n\n private constructor(value: string, config: SecureConfig) {\n super();\n this.#encryptedValue = config.encryptionProvider.encrypt(value);\n this.#data = this.parseConnectionString(\n value,\n config.secretKeys.map((x) => x.toLocaleLowerCase()),\n config,\n );\n }\n\n private parseConnectionString(value: string, secretKeys: SecureKeys, config: SecureConfig): [string, string | SecureString][] {\n return value\n .split(';')\n .filter(Boolean)\n .map((pair) => {\n const [key, value] = pair.split('=');\n const v = value ?? '';\n const val = secretKeys.includes(key.toLocaleLowerCase()) ? SecureString.from(v, config) : v;\n return [key, val];\n });\n }\n\n static factory(config: SecureConfig): (value: string) => SecureConnectionString {\n return (value: string) => SecureConnectionString.from(value, config);\n }\n\n public static from<T extends string | null | undefined>(value: T, config: SecureConfig): T extends string ? SecureConnectionString : T {\n if (value === null) {\n return null as T extends string ? SecureConnectionString : T;\n }\n if (value === undefined) {\n return undefined as T extends string ? SecureConnectionString : T;\n }\n return new SecureConnectionString(value, config) as T extends string ? SecureConnectionString : T;\n }\n\n public override toString(): string {\n return this.#data.map(([key, value]) => `${key}=${value}`).join(';');\n }\n\n public override toJSON(): object {\n return Object.fromEntries(this.#data);\n }\n\n public override [util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string {\n if (depth < 0) {\n return '[SecureConnectionString]';\n }\n const newOptions = Object.assign({}, options, {\n depth: options.depth == null ? null : options.depth - 1,\n });\n return inspect(this.toJSON(), newOptions);\n }\n}\n","import util, { type InspectOptions } from 'node:util';\nimport { SecureString } from './SecureString';\nimport { ISecureURL } from './interfaces';\nimport type { IEncryptedValue, InspectFunction, SecureConfig } from './types';\n\ntype UrlObject = {\n href: string;\n password?: string;\n searchParams?: Record<string, string>;\n};\n\nexport class SecureURL extends ISecureURL {\n readonly #encryptedValue: IEncryptedValue;\n readonly #password: SecureString | null;\n\n public get secretValue(): URL {\n return new URL(this.#encryptedValue.getValue());\n }\n\n private constructor(value: URL, config: SecureConfig) {\n super();\n this.#encryptedValue = config.encryptionProvider.encrypt(value.href);\n this.#password = SecureString.from(value.password || null, config);\n }\n\n static factory(config: SecureConfig): (value: URL) => ISecureURL {\n return (value: URL) => SecureURL.from(value, config);\n }\n\n public static from<T extends URL | null | undefined>(value: T, config: SecureConfig): T extends URL ? SecureURL : T {\n if (value === null) {\n return null as T extends URL ? SecureURL : T;\n }\n if (value === undefined) {\n return undefined as T extends URL ? SecureURL : T;\n }\n return new SecureURL(value, config) as T extends URL ? SecureURL : T;\n }\n\n override toString(): string {\n const originalUrl = this.secretValue;\n const newUrl = new URL(originalUrl.href);\n if (this.#password !== null) {\n newUrl.password = this.#password.toString();\n }\n return newUrl.href;\n }\n\n override toJSON(): UrlObject {\n const originalUrl = this.secretValue;\n const newUrl = new URL(originalUrl.href);\n newUrl.password = '';\n\n const searchParams = new URLSearchParams(newUrl.searchParams);\n newUrl.search = '';\n\n let password: string | undefined;\n if (this.#password !== null) {\n password = this.#password.toString();\n }\n\n const result: UrlObject = {\n href: newUrl.href,\n };\n if (password !== undefined) {\n result.password = password;\n }\n if (searchParams.size > 0) {\n result.searchParams = Object.fromEntries(searchParams);\n }\n return result;\n }\n override [util.inspect.custom](depth: number, options: InspectOptions, inspect: InspectFunction): string {\n if (depth < 0) {\n return '[SecureURL]';\n }\n const newOptions = Object.assign({}, options, {\n depth: options.depth == null ? null : options.depth - 1,\n });\n return inspect(this.toJSON(), newOptions);\n }\n}\n","import type { SecureKeys } from './types';\n\nexport const defaultSecureKeys = ['AccessKey', 'SharedAccessKey', 'Password', 'AccountKey', 'Secret', 'SecretKey', 'ApiKey', 'Token', 'Key', 'MasterKey', 'PrimaryKey', 'SecondaryKey'] as const satisfies SecureKeys;\n","import { EncryptedValue } from './EncryptedValue';\nimport { SecureConnectionString } from './SecureConnectionString';\nimport { SecureString } from './SecureString';\nimport { SecureURL } from './SecureURL';\nimport { defaultSecureKeys } from './defaults';\nimport type { ISecureFactory } from './interfaces';\nimport type { IEncryptionProvider, SecureConfig } from './types';\n\nexport const defaultEncryptionProvider: IEncryptionProvider = {\n encrypt: (value: string) => new EncryptedValue(value),\n};\n\nexport const createFactory = (options?: Partial<SecureConfig>): ISecureFactory => {\n const config: SecureConfig = {\n secret: options?.secret ?? null,\n encryptionProvider: options?.encryptionProvider ?? defaultEncryptionProvider,\n secretKeys: options?.secretKeys ?? defaultSecureKeys,\n };\n\n return {\n string: SecureString.factory(config),\n connectionString: SecureConnectionString.factory(config),\n url: SecureURL.factory(config),\n };\n};\n"]}
|