@nivinjoseph/n-sec 5.0.3 → 5.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/dist/bin.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/bin.js ADDED
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const tslib_1 = require("tslib");
5
+ // import { given } from "@nivinjoseph/n-defensive";
6
+ const n_util_1 = require("@nivinjoseph/n-util");
7
+ const symmetric_encryption_1 = require("./crypto/symmetric-encryption");
8
+ var SupportedCommands;
9
+ (function (SupportedCommands) {
10
+ SupportedCommands["generateSymmetricKey"] = "generate-symmetric-key";
11
+ })(SupportedCommands || (SupportedCommands = {}));
12
+ const supportedCommandsString = JSON.stringify(n_util_1.TypeHelper.enumTypeToTuples(SupportedCommands).map(t => t[1]));
13
+ function executeCommand(command) {
14
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
15
+ // given(command, "command").ensureHasValue().ensureIsString();
16
+ switch (command) {
17
+ case SupportedCommands.generateSymmetricKey:
18
+ {
19
+ const key = yield symmetric_encryption_1.SymmetricEncryption.generateKey();
20
+ console.log("SYMMETRIC KEY => ", key);
21
+ break;
22
+ }
23
+ default:
24
+ console.error(`Unknown command '${command}'. Supported commands are ${supportedCommandsString}.`);
25
+ }
26
+ });
27
+ }
28
+ const args = process.argv.slice(2);
29
+ if (args.length !== 1) {
30
+ console.error(`Please enter a single command. Supported commands are ${supportedCommandsString}.`);
31
+ process.exit(1); //an error occurred
32
+ }
33
+ const command = args[0];
34
+ executeCommand(command)
35
+ .then(() => process.exit(0))
36
+ .catch(e => {
37
+ console.error("Error occurred");
38
+ console.error(e);
39
+ process.exit(1);
40
+ });
41
+ //# sourceMappingURL=bin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/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C;IAChC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACjB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"}
@@ -26,7 +26,8 @@ class Hash {
26
26
  };
27
27
  const valueReverse = reverse(value);
28
28
  const saltReverse = reverse(salt);
29
- const saltedValue = "{1}{0}{2}{1}{3}{1}{2}".format(value, salt, valueReverse, saltReverse);
29
+ // const saltedValue = "{1}{0}{2}{1}{3}{1}{2}".format(value, salt, valueReverse, saltReverse);
30
+ const saltedValue = `${salt}${value}${valueReverse}${salt}${saltReverse}${salt}${valueReverse}`;
30
31
  return Hash.create(saltedValue);
31
32
  }
32
33
  }
@@ -1 +1 @@
1
- {"version":3,"file":"hash.js","sourceRoot":"","sources":["../../src/crypto/hash.ts"],"names":[],"mappings":";;;AAAA,0DAAiD;AACjD,iCAAiC;AAGjC,SAAS;AACT,MAAa,IAAI;IAEb,gBAAwB,CAAC;IAGlB,MAAM,CAAC,MAAM,CAAC,KAAa;QAE9B,IAAA,mBAAK,EAAC,KAAK,EAAE,OAAO,CAAC,CAAC,cAAc,EAAE,CAAC,cAAc,EAAE,CAAC;QACxD,KAAK,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;QAErB,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QACzC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAC3B,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC;IAC5C,CAAC;IAEM,MAAM,CAAC,eAAe,CAAC,KAAa,EAAE,IAAY;QAErD,IAAA,mBAAK,EAAC,KAAK,EAAE,OAAO,CAAC,CAAC,cAAc,EAAE,CAAC,cAAc,EAAE,CAAC;QACxD,IAAA,mBAAK,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC,cAAc,EAAE,CAAC,cAAc,EAAE,CAAC;QAEtD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AAC,eAAe,CAAC,KAAa,EAAE,IAAY;QAErD,IAAA,mBAAK,EAAC,KAAK,EAAE,OAAO,CAAC,CAAC,cAAc,EAAE,CAAC,cAAc,EAAE,CAAC;QACxD,IAAA,mBAAK,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC,cAAc,EAAE,CAAC,cAAc,EAAE,CAAC;QAEtD,KAAK,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;QACrB,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAEnB,MAAM,OAAO,GAAG,CAAC,GAAW,EAAU,EAAE;YAEpC,IAAI,GAAG,GAAG,EAAE,CAAC;YACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE;gBAC/B,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;YACvB,OAAO,GAAG,CAAC;QACf,CAAC,CAAC;QAEF,MAAM,YAAY,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;QACpC,MAAM,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;QAElC,8FAA8F;QAE9F,MAAM,WAAW,GAAG,GAAG,IAAI,GAAG,KAAK,GAAG,YAAY,GAAG,IAAI,GAAG,WAAW,GAAG,IAAI,GAAG,YAAY,EAAE,CAAC;QAEhG,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IACpC,CAAC;CACJ;AAxCD,oBAwCC"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import "@nivinjoseph/n-ext";
1
2
  import { SymmetricEncryption } from "./crypto/symmetric-encryption";
2
3
  import { Hmac } from "./crypto/hmac";
3
4
  import { Hash } from "./crypto/hash";
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SecurityToken = exports.JsonWebToken = exports.InvalidTokenException = exports.ExpiredTokenException = exports.ClaimsIdentity = exports.Claim = exports.AlgType = exports.CryptoException = exports.Hash = exports.Hmac = exports.SymmetricEncryption = void 0;
4
+ require("@nivinjoseph/n-ext");
4
5
  const symmetric_encryption_1 = require("./crypto/symmetric-encryption");
5
6
  Object.defineProperty(exports, "SymmetricEncryption", { enumerable: true, get: function () { return symmetric_encryption_1.SymmetricEncryption; } });
6
7
  const hmac_1 = require("./crypto/hmac");
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,wEAAoE;AAkBhE,oGAlBK,0CAAmB,OAkBL;AAjBvB,wCAAqC;AAiBZ,qFAjBhB,WAAI,OAiBgB;AAhB7B,wCAAqC;AAgBN,qFAhBtB,WAAI,OAgBsB;AAfnC,iEAAiE;AACjE,yEAAyE;AACzE,gEAA4D;AAexD,gGAfK,kCAAe,OAeL;AAbnB,sDAAkD;AAe9C,wFAfK,kBAAO,OAeL;AAdX,gDAA6C;AAchC,sFAdJ,aAAK,OAcI;AAblB,oEAAgE;AAa5C,+FAbX,gCAAc,OAaW;AAZlC,oFAA+E;AAY3C,sGAZ3B,+CAAqB,OAY2B;AAXzD,oFAA+E;AAWpB,sGAXlD,+CAAqB,OAWkD;AAVhF,kEAA6D;AAUqB,6FAVzE,6BAAY,OAUyE;AAT9F,kEAA8D;AASkC,8FATvF,8BAAa,OASuF"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,8BAA4B;AAE5B,wEAAoE;AAkBhE,oGAlBK,0CAAmB,OAkBL;AAjBvB,wCAAqC;AAiBZ,qFAjBhB,WAAI,OAiBgB;AAhB7B,wCAAqC;AAgBN,qFAhBtB,WAAI,OAgBsB;AAfnC,iEAAiE;AACjE,yEAAyE;AACzE,gEAA4D;AAexD,gGAfK,kCAAe,OAeL;AAbnB,sDAAkD;AAe9C,wFAfK,kBAAO,OAeL;AAdX,gDAA6C;AAchC,sFAdJ,aAAK,OAcI;AAblB,oEAAgE;AAa5C,+FAbX,gCAAc,OAaW;AAZlC,oFAA+E;AAY3C,sGAZ3B,+CAAqB,OAY2B;AAXzD,oFAA+E;AAWpB,sGAXlD,+CAAqB,OAWkD;AAVhF,kEAA6D;AAUqB,6FAVzE,6BAAY,OAUyE;AAT9F,kEAA8D;AASkC,8FATvF,8BAAa,OASuF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nivinjoseph/n-sec",
3
- "version": "5.0.3",
3
+ "version": "5.0.5",
4
4
  "description": "Security library",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -17,6 +17,7 @@
17
17
  "test-ci": "mocha --timeout 5000 --reporter spec --ui tdd --require ts-node/register './test/**/*.test.js'",
18
18
  "publish-package": "npm run ts-build-dist && git add . && git commit -m 'preparing to publish new version' && npm version patch && git push && npm publish --access=public"
19
19
  },
20
+ "bin": "./dist/bin.js",
20
21
  "repository": {
21
22
  "type": "git",
22
23
  "url": "git+https://github.com/nivinjoseph/n-sec.git"
@@ -44,6 +45,7 @@
44
45
  "dependencies": {
45
46
  "@nivinjoseph/n-defensive": "^1.0.41",
46
47
  "@nivinjoseph/n-exception": "^1.0.26",
47
- "@nivinjoseph/n-ext": "^1.1.36"
48
+ "@nivinjoseph/n-ext": "^1.1.36",
49
+ "@nivinjoseph/n-util": "^1.0.81"
48
50
  }
49
51
  }
package/src/bin.ts ADDED
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env node
2
+
3
+ // import { given } from "@nivinjoseph/n-defensive";
4
+ import { TypeHelper } from "@nivinjoseph/n-util";
5
+ import { SymmetricEncryption } from "./crypto/symmetric-encryption";
6
+
7
+ enum SupportedCommands
8
+ {
9
+ generateSymmetricKey = "generate-symmetric-key"
10
+ }
11
+
12
+ const supportedCommandsString = JSON.stringify(TypeHelper.enumTypeToTuples(SupportedCommands).map(t => t[1]));
13
+
14
+ async function executeCommand(command: SupportedCommands): Promise<void>
15
+ {
16
+ // given(command, "command").ensureHasValue().ensureIsString();
17
+
18
+ switch (command)
19
+ {
20
+ case SupportedCommands.generateSymmetricKey:
21
+ {
22
+ const key = await SymmetricEncryption.generateKey();
23
+ console.log("SYMMETRIC KEY => ", key);
24
+ break;
25
+ }
26
+ default:
27
+ console.error(`Unknown command '${command}'. Supported commands are ${supportedCommandsString}.`);
28
+ }
29
+ }
30
+
31
+ const args = process.argv.slice(2);
32
+
33
+ if (args.length !== 1)
34
+ {
35
+ console.error(`Please enter a single command. Supported commands are ${supportedCommandsString}.`);
36
+ process.exit(1); //an error occurred
37
+ }
38
+
39
+ const command = args[0] as SupportedCommands;
40
+
41
+ executeCommand(command)
42
+ .then(() => process.exit(0))
43
+ .catch(e =>
44
+ {
45
+ console.error("Error occurred");
46
+ console.error(e);
47
+ process.exit(1);
48
+ });
49
+
@@ -37,7 +37,9 @@ export class Hash
37
37
  const valueReverse = reverse(value);
38
38
  const saltReverse = reverse(salt);
39
39
 
40
- const saltedValue = "{1}{0}{2}{1}{3}{1}{2}".format(value, salt, valueReverse, saltReverse);
40
+ // const saltedValue = "{1}{0}{2}{1}{3}{1}{2}".format(value, salt, valueReverse, saltReverse);
41
+
42
+ const saltedValue = `${salt}${value}${valueReverse}${salt}${saltReverse}${salt}${valueReverse}`;
41
43
 
42
44
  return Hash.create(saltedValue);
43
45
  }
package/src/index.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import "@nivinjoseph/n-ext";
2
+
1
3
  import { SymmetricEncryption } from "./crypto/symmetric-encryption";
2
4
  import { Hmac } from "./crypto/hmac";
3
5
  import { Hash } from "./crypto/hash";
package/test/hash.test.ts CHANGED
@@ -149,6 +149,21 @@ suite("Hash", () =>
149
149
  Assert.notStrictEqual(hash1, hash2);
150
150
  });
151
151
 
152
+ test("regex issue", () =>
153
+ {
154
+ let password = "YQAt3TPI7s1YXyClbQ2$&JdHOKZJ@z4!";
155
+ password = password.trim();
156
+
157
+ const createdAt = Date.now();
158
+ const username = "defaultUser";
159
+
160
+ const salt = (createdAt % 2) === 0
161
+ ? `${username.base64Decode()}${createdAt}`
162
+ : `${createdAt}${username.base64Decode()}`;
163
+
164
+ return Hash.createUsingSalt(password, salt);
165
+ });
166
+
152
167
 
153
168
 
154
169