@resq-systems/security 1.0.4 → 1.0.5

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/lib/hash.d.mts ADDED
@@ -0,0 +1,38 @@
1
+ //#region src/hash.d.ts
2
+ /**
3
+ * Copyright 2026 ResQ Systems, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ /**
18
+ * Hash a string using the FNV-1a algorithm.
19
+ *
20
+ * Generates a deterministic hash value for a given string using a variant of the FNV-1a
21
+ * (Fowler-Noll-Vo) algorithm. The hash is returned as a string representation of a 32-bit integer.
22
+ */
23
+ declare function getHashForString(string: string): string;
24
+ /**
25
+ * Hash an object by converting it to JSON and then hashing the resulting string.
26
+ */
27
+ declare function getHashForObject(obj: unknown): string;
28
+ /**
29
+ * Hash an ArrayBuffer using the FNV-1a algorithm.
30
+ */
31
+ declare function getHashForBuffer(buffer: ArrayBuffer): string;
32
+ /**
33
+ * Applies a string transformation algorithm that rearranges and modifies characters.
34
+ */
35
+ declare function lns(str: string): string;
36
+ //#endregion
37
+ export { getHashForBuffer, getHashForObject, getHashForString, lns };
38
+ //# sourceMappingURL=hash.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash.d.mts","names":[],"sources":["../src/hash.ts"],"mappings":";;AAsBA;;;;;AAYA;;;;;AAOA;;;;;AAaA;;;;;iBAhCgB,gBAAA,CAAiB,MAAA;;;;iBAYjB,gBAAA,CAAiB,GAAA;;;;iBAOjB,gBAAA,CAAiB,MAAA,EAAQ,WAAA;;;;iBAazB,GAAA,CAAI,GAAA"}
package/lib/hash.mjs ADDED
@@ -0,0 +1,66 @@
1
+ //#region src/hash.ts
2
+ /**
3
+ * Copyright 2026 ResQ Systems, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ /**
18
+ * Hash a string using the FNV-1a algorithm.
19
+ *
20
+ * Generates a deterministic hash value for a given string using a variant of the FNV-1a
21
+ * (Fowler-Noll-Vo) algorithm. The hash is returned as a string representation of a 32-bit integer.
22
+ */
23
+ function getHashForString(string) {
24
+ let hash = 0;
25
+ for (let i = 0; i < string.length; i++) {
26
+ hash = (hash << 5) - hash + string.charCodeAt(i);
27
+ hash |= 0;
28
+ }
29
+ return `${hash}`;
30
+ }
31
+ /**
32
+ * Hash an object by converting it to JSON and then hashing the resulting string.
33
+ */
34
+ function getHashForObject(obj) {
35
+ return getHashForString(JSON.stringify(obj));
36
+ }
37
+ /**
38
+ * Hash an ArrayBuffer using the FNV-1a algorithm.
39
+ */
40
+ function getHashForBuffer(buffer) {
41
+ const view = new DataView(buffer);
42
+ let hash = 0;
43
+ for (let i = 0; i < view.byteLength; i++) {
44
+ hash = (hash << 5) - hash + view.getUint8(i);
45
+ hash |= 0;
46
+ }
47
+ return `${hash}`;
48
+ }
49
+ /**
50
+ * Applies a string transformation algorithm that rearranges and modifies characters.
51
+ */
52
+ function lns(str) {
53
+ const result = str.split("");
54
+ result.push(...result.splice(0, Math.round(result.length / 5)));
55
+ result.push(...result.splice(0, Math.round(result.length / 4)));
56
+ result.push(...result.splice(0, Math.round(result.length / 3)));
57
+ result.push(...result.splice(0, Math.round(result.length / 2)));
58
+ return result.reverse().map((n) => {
59
+ const num = Number(n);
60
+ return Number.isNaN(num) || n.trim() === "" ? n : num < 5 ? String(5 + num) : num > 5 ? String(num - 5) : n;
61
+ }).join("");
62
+ }
63
+ //#endregion
64
+ export { getHashForBuffer, getHashForObject, getHashForString, lns };
65
+
66
+ //# sourceMappingURL=hash.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash.mjs","names":[],"sources":["../src/hash.ts"],"sourcesContent":["/**\n * Copyright 2026 ResQ Systems, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * Hash a string using the FNV-1a algorithm.\n *\n * Generates a deterministic hash value for a given string using a variant of the FNV-1a\n * (Fowler-Noll-Vo) algorithm. The hash is returned as a string representation of a 32-bit integer.\n */\nexport function getHashForString(string: string): string {\n\tlet hash = 0;\n\tfor (let i = 0; i < string.length; i++) {\n\t\thash = (hash << 5) - hash + string.charCodeAt(i);\n\t\thash |= 0; // Convert to 32bit integer\n\t}\n\treturn `${hash}`;\n}\n\n/**\n * Hash an object by converting it to JSON and then hashing the resulting string.\n */\nexport function getHashForObject(obj: unknown): string {\n\treturn getHashForString(JSON.stringify(obj));\n}\n\n/**\n * Hash an ArrayBuffer using the FNV-1a algorithm.\n */\nexport function getHashForBuffer(buffer: ArrayBuffer): string {\n\tconst view = new DataView(buffer);\n\tlet hash = 0;\n\tfor (let i = 0; i < view.byteLength; i++) {\n\t\thash = (hash << 5) - hash + view.getUint8(i);\n\t\thash |= 0; // Convert to 32bit integer\n\t}\n\treturn `${hash}`;\n}\n\n/**\n * Applies a string transformation algorithm that rearranges and modifies characters.\n */\nexport function lns(str: string): string {\n\tconst result = str.split(\"\");\n\tresult.push(...result.splice(0, Math.round(result.length / 5)));\n\tresult.push(...result.splice(0, Math.round(result.length / 4)));\n\tresult.push(...result.splice(0, Math.round(result.length / 3)));\n\tresult.push(...result.splice(0, Math.round(result.length / 2)));\n\treturn result\n\t\t.reverse()\n\t\t.map((n) => {\n\t\t\tconst num = Number(n);\n\t\t\treturn Number.isNaN(num) || n.trim() === \"\"\n\t\t\t\t? n\n\t\t\t\t: num < 5\n\t\t\t\t\t? String(5 + num)\n\t\t\t\t\t: num > 5\n\t\t\t\t\t\t? String(num - 5)\n\t\t\t\t\t\t: n;\n\t\t})\n\t\t.join(\"\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,iBAAiB,QAAwB;CACxD,IAAI,OAAO;AACX,MAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;AACvC,UAAQ,QAAQ,KAAK,OAAO,OAAO,WAAW,EAAE;AAChD,UAAQ;;AAET,QAAO,GAAG;;;;;AAMX,SAAgB,iBAAiB,KAAsB;AACtD,QAAO,iBAAiB,KAAK,UAAU,IAAI,CAAC;;;;;AAM7C,SAAgB,iBAAiB,QAA6B;CAC7D,MAAM,OAAO,IAAI,SAAS,OAAO;CACjC,IAAI,OAAO;AACX,MAAK,IAAI,IAAI,GAAG,IAAI,KAAK,YAAY,KAAK;AACzC,UAAQ,QAAQ,KAAK,OAAO,KAAK,SAAS,EAAE;AAC5C,UAAQ;;AAET,QAAO,GAAG;;;;;AAMX,SAAgB,IAAI,KAAqB;CACxC,MAAM,SAAS,IAAI,MAAM,GAAG;AAC5B,QAAO,KAAK,GAAG,OAAO,OAAO,GAAG,KAAK,MAAM,OAAO,SAAS,EAAE,CAAC,CAAC;AAC/D,QAAO,KAAK,GAAG,OAAO,OAAO,GAAG,KAAK,MAAM,OAAO,SAAS,EAAE,CAAC,CAAC;AAC/D,QAAO,KAAK,GAAG,OAAO,OAAO,GAAG,KAAK,MAAM,OAAO,SAAS,EAAE,CAAC,CAAC;AAC/D,QAAO,KAAK,GAAG,OAAO,OAAO,GAAG,KAAK,MAAM,OAAO,SAAS,EAAE,CAAC,CAAC;AAC/D,QAAO,OACL,SAAS,CACT,KAAK,MAAM;EACX,MAAM,MAAM,OAAO,EAAE;AACrB,SAAO,OAAO,MAAM,IAAI,IAAI,EAAE,MAAM,KAAK,KACtC,IACA,MAAM,IACL,OAAO,IAAI,IAAI,GACf,MAAM,IACL,OAAO,MAAM,EAAE,GACf;GACJ,CACD,KAAK,GAAG"}
package/lib/index.d.mts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Ciphertext, EncryptionKey, Masked, SecureToken, Sha256Hex, coerceCiphertext, coerceEncryptionKey, decryptData, encryptData, generateSecureToken, hashData, isCiphertext, isEncryptionKey, maskEmail, maskPII, sanitizeForLogging, toCiphertext, toEncryptionKey, unsafeCiphertext, unsafeEncryptionKey } from "./crypto.mjs";
2
+ import { getHashForBuffer, getHashForObject, getHashForString, lns } from "./hash.mjs";
2
3
  import { THREAT_DETECTED_MESSAGE, ThreatDetectionConfig, ThreatDetectionResult, ThreatFinding, ThreatType, containsCommandInjection, containsHomoglyphs, containsNoSQLInjection, containsPathTraversal, containsSQLInjection, containsXSSPatterns, detectThreatPatterns, getThreatErrorMessage, isSafeInput, normalizeUnicode, sanitizeForDisplay, validateSafeEmail, validateSafeName, validateSafeText } from "./validators.mjs";
3
4
  import { CreditCard, CreditCardSchema, Email, EmailSchema, IPv4, IPv4Schema, PIIRedactionOptions, PIIRedactionOptionsSchema, PhoneNumber, PhoneNumberSchema, SSN, SSNSchema, SafeUrl, SafeUrlSchema, SanitizedString, SanitizedStringSchema, UrlProtocol, UrlProtocolSchema, UserInputOptions, UserInputOptionsSchema, escapeHtml, isValidEmail, isValidPhone, isValidSSN, isValidUrl, parseJsonWithSchema, redactPII, redactPIIEffect, safeStringify, sanitizeHtml, sanitizeJson, sanitizeUrl, sanitizeUrlEffect, stripAnsi, validateUserInput, validateUserInputEffect } from "./sanitize.mjs";
4
- export { Ciphertext, CreditCard, CreditCardSchema, Email, EmailSchema, EncryptionKey, IPv4, IPv4Schema, Masked, PIIRedactionOptions, PIIRedactionOptionsSchema, PhoneNumber, PhoneNumberSchema, SSN, SSNSchema, SafeUrl, SafeUrlSchema, SanitizedString, SanitizedStringSchema, SecureToken, Sha256Hex, THREAT_DETECTED_MESSAGE, ThreatDetectionConfig, ThreatDetectionResult, ThreatFinding, ThreatType, UrlProtocol, UrlProtocolSchema, UserInputOptions, UserInputOptionsSchema, coerceCiphertext, coerceEncryptionKey, containsCommandInjection, containsHomoglyphs, containsNoSQLInjection, containsPathTraversal, containsSQLInjection, containsXSSPatterns, decryptData, detectThreatPatterns, encryptData, escapeHtml, generateSecureToken, getThreatErrorMessage, hashData, isCiphertext, isEncryptionKey, isSafeInput, isValidEmail, isValidPhone, isValidSSN, isValidUrl, maskEmail, maskPII, normalizeUnicode, parseJsonWithSchema, redactPII, redactPIIEffect, safeStringify, sanitizeForDisplay, sanitizeForLogging, sanitizeHtml, sanitizeJson, sanitizeUrl, sanitizeUrlEffect, stripAnsi, toCiphertext, toEncryptionKey, unsafeCiphertext, unsafeEncryptionKey, validateSafeEmail, validateSafeName, validateSafeText, validateUserInput, validateUserInputEffect };
5
+ export { Ciphertext, CreditCard, CreditCardSchema, Email, EmailSchema, EncryptionKey, IPv4, IPv4Schema, Masked, PIIRedactionOptions, PIIRedactionOptionsSchema, PhoneNumber, PhoneNumberSchema, SSN, SSNSchema, SafeUrl, SafeUrlSchema, SanitizedString, SanitizedStringSchema, SecureToken, Sha256Hex, THREAT_DETECTED_MESSAGE, ThreatDetectionConfig, ThreatDetectionResult, ThreatFinding, ThreatType, UrlProtocol, UrlProtocolSchema, UserInputOptions, UserInputOptionsSchema, coerceCiphertext, coerceEncryptionKey, containsCommandInjection, containsHomoglyphs, containsNoSQLInjection, containsPathTraversal, containsSQLInjection, containsXSSPatterns, decryptData, detectThreatPatterns, encryptData, escapeHtml, generateSecureToken, getHashForBuffer, getHashForObject, getHashForString, getThreatErrorMessage, hashData, isCiphertext, isEncryptionKey, isSafeInput, isValidEmail, isValidPhone, isValidSSN, isValidUrl, lns, maskEmail, maskPII, normalizeUnicode, parseJsonWithSchema, redactPII, redactPIIEffect, safeStringify, sanitizeForDisplay, sanitizeForLogging, sanitizeHtml, sanitizeJson, sanitizeUrl, sanitizeUrlEffect, stripAnsi, toCiphertext, toEncryptionKey, unsafeCiphertext, unsafeEncryptionKey, validateSafeEmail, validateSafeName, validateSafeText, validateUserInput, validateUserInputEffect };
package/lib/index.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  import { coerceCiphertext, coerceEncryptionKey, decryptData, encryptData, generateSecureToken, hashData, isCiphertext, isEncryptionKey, maskEmail, maskPII, sanitizeForLogging, toCiphertext, toEncryptionKey, unsafeCiphertext, unsafeEncryptionKey } from "./crypto.mjs";
2
+ import { getHashForBuffer, getHashForObject, getHashForString, lns } from "./hash.mjs";
2
3
  import { THREAT_DETECTED_MESSAGE, containsCommandInjection, containsHomoglyphs, containsNoSQLInjection, containsPathTraversal, containsSQLInjection, containsXSSPatterns, detectThreatPatterns, getThreatErrorMessage, isSafeInput, normalizeUnicode, sanitizeForDisplay, validateSafeEmail, validateSafeName, validateSafeText } from "./validators.mjs";
3
4
  import { CreditCardSchema, EmailSchema, IPv4Schema, PIIRedactionOptionsSchema, PhoneNumberSchema, SSNSchema, SafeUrlSchema, SanitizedStringSchema, UrlProtocolSchema, UserInputOptionsSchema, escapeHtml, isValidEmail, isValidPhone, isValidSSN, isValidUrl, parseJsonWithSchema, redactPII, redactPIIEffect, safeStringify, sanitizeHtml, sanitizeJson, sanitizeUrl, sanitizeUrlEffect, stripAnsi, validateUserInput, validateUserInputEffect } from "./sanitize.mjs";
4
- export { CreditCardSchema, EmailSchema, IPv4Schema, PIIRedactionOptionsSchema, PhoneNumberSchema, SSNSchema, SafeUrlSchema, SanitizedStringSchema, THREAT_DETECTED_MESSAGE, UrlProtocolSchema, UserInputOptionsSchema, coerceCiphertext, coerceEncryptionKey, containsCommandInjection, containsHomoglyphs, containsNoSQLInjection, containsPathTraversal, containsSQLInjection, containsXSSPatterns, decryptData, detectThreatPatterns, encryptData, escapeHtml, generateSecureToken, getThreatErrorMessage, hashData, isCiphertext, isEncryptionKey, isSafeInput, isValidEmail, isValidPhone, isValidSSN, isValidUrl, maskEmail, maskPII, normalizeUnicode, parseJsonWithSchema, redactPII, redactPIIEffect, safeStringify, sanitizeForDisplay, sanitizeForLogging, sanitizeHtml, sanitizeJson, sanitizeUrl, sanitizeUrlEffect, stripAnsi, toCiphertext, toEncryptionKey, unsafeCiphertext, unsafeEncryptionKey, validateSafeEmail, validateSafeName, validateSafeText, validateUserInput, validateUserInputEffect };
5
+ export { CreditCardSchema, EmailSchema, IPv4Schema, PIIRedactionOptionsSchema, PhoneNumberSchema, SSNSchema, SafeUrlSchema, SanitizedStringSchema, THREAT_DETECTED_MESSAGE, UrlProtocolSchema, UserInputOptionsSchema, coerceCiphertext, coerceEncryptionKey, containsCommandInjection, containsHomoglyphs, containsNoSQLInjection, containsPathTraversal, containsSQLInjection, containsXSSPatterns, decryptData, detectThreatPatterns, encryptData, escapeHtml, generateSecureToken, getHashForBuffer, getHashForObject, getHashForString, getThreatErrorMessage, hashData, isCiphertext, isEncryptionKey, isSafeInput, isValidEmail, isValidPhone, isValidSSN, isValidUrl, lns, maskEmail, maskPII, normalizeUnicode, parseJsonWithSchema, redactPII, redactPIIEffect, safeStringify, sanitizeForDisplay, sanitizeForLogging, sanitizeHtml, sanitizeJson, sanitizeUrl, sanitizeUrlEffect, stripAnsi, toCiphertext, toEncryptionKey, unsafeCiphertext, unsafeEncryptionKey, validateSafeEmail, validateSafeName, validateSafeText, validateUserInput, validateUserInputEffect };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@resq-systems/security",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "Security utilities: encryption, input validation, schemas, and PII sanitization",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -52,7 +52,7 @@
52
52
  "devDependencies": {
53
53
  "@total-typescript/ts-reset": "^0.6.1",
54
54
  "@types/node": "^26.1.1",
55
- "effect": "4.0.0-beta.97",
55
+ "effect": "4.0.0-beta.98",
56
56
  "jsdom": "^29.1.1",
57
57
  "tsdown": "^0.22.4",
58
58
  "typescript": "7.0.2",