@tsed/jwks 7.0.0-alpha.1 → 7.0.0-beta.10

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/jest.config.js ADDED
@@ -0,0 +1,14 @@
1
+ // For a detailed explanation regarding each configuration property, visit:
2
+ // https://jestjs.io/docs/en/configuration.html
3
+
4
+ module.exports = {
5
+ ...require("@tsed/jest-config")(__dirname, "jwk"),
6
+ coverageThreshold: {
7
+ global: {
8
+ statements: 100,
9
+ branches: 85.71,
10
+ functions: 100,
11
+ lines: 100
12
+ }
13
+ }
14
+ };
@@ -9,7 +9,7 @@ function generateJwks(options = {}) {
9
9
  const keystore = new jose2_1.JWKS.KeyStore();
10
10
  if (certificates) {
11
11
  certificates.forEach(({ path, ...options }) => {
12
- const content = fs_extra_1.readFileSync(path, { encoding: "utf-8" });
12
+ const content = (0, fs_extra_1.readFileSync)(path, { encoding: "utf-8" });
13
13
  const isPrivate = content.includes("PRIVATE KEY");
14
14
  if (!isPrivate) {
15
15
  keystore.add(jose2_1.JWK.asKey(content, options));
@@ -25,12 +25,12 @@ function generateJwks(options = {}) {
25
25
  }
26
26
  exports.generateJwks = generateJwks;
27
27
  function getJwks(options) {
28
- fs_extra_1.ensureDirSync(path_1.dirname(options.path));
29
- if (!fs_extra_1.existsSync(options.path)) {
28
+ (0, fs_extra_1.ensureDirSync)((0, path_1.dirname)(options.path));
29
+ if (!(0, fs_extra_1.existsSync)(options.path)) {
30
30
  const keys = generateJwks(options);
31
- fs_extra_1.writeFileSync(options.path, JSON.stringify(keys, null, 2));
31
+ (0, fs_extra_1.writeFileSync)(options.path, JSON.stringify(keys, null, 2));
32
32
  }
33
- return JSON.parse(fs_extra_1.readFileSync(options.path, { encoding: "utf-8" }));
33
+ return JSON.parse((0, fs_extra_1.readFileSync)(options.path, { encoding: "utf-8" }));
34
34
  }
35
35
  exports.getJwks = getJwks;
36
36
  //# sourceMappingURL=getJwks.js.map
@@ -0,0 +1 @@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AAC,CAAC,CAAC;IAErC,IAAI,CAAC,IAAA,qBAAU,EAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QAC7B,MAAM,IAAI,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;QACnC,IAAA,wBAAa,EAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;KAC5D;IAED,OAAO,IAAI,CAAC,KAAK,CAAC,IAAA,uBAAY,EAAC,OAAO,CAAC,IAAI,EAAE,EAAC,QAAQ,EAAE,OAAO,EAAC,CAAC,CAAC,CAAC;AACrE,CAAC;AATD,0BASC","sourcesContent":["import {ensureDirSync, existsSync, readFileSync, writeFileSync} from \"fs-extra\";\nimport {JWK, JWKS, KeyParameters} from \"jose2\";\nimport {dirname} from \"path\";\n\nexport interface JwksKeyParameters extends KeyParameters {\n path: string;\n}\n\nexport interface JwksOptions {\n path: string;\n certificates?: JwksKeyParameters[];\n}\n\nexport function generateJwks(options: Partial<JwksOptions> = {}) {\n const {certificates} = options;\n const keystore = new JWKS.KeyStore();\n\n if (certificates) {\n certificates.forEach(({path, ...options}) => {\n const content = readFileSync(path, {encoding: \"utf-8\"});\n const isPrivate = content.includes(\"PRIVATE KEY\");\n\n if (!isPrivate) {\n keystore.add(JWK.asKey(content, options));\n }\n });\n } else {\n keystore.generateSync(\"RSA\", 2048, {use: \"sig\"});\n keystore.generateSync(\"EC\", \"P-256\", {use: \"sig\", alg: \"ES256\"});\n keystore.generateSync(\"OKP\", \"Ed25519\", {use: \"sig\", alg: \"EdDSA\"});\n }\n\n return keystore.toJWKS(true);\n}\n\nexport function getJwks(options: JwksOptions) {\n ensureDirSync(dirname(options.path));\n\n if (!existsSync(options.path)) {\n const keys = generateJwks(options);\n writeFileSync(options.path, JSON.stringify(keys, null, 2));\n }\n\n return JSON.parse(readFileSync(options.path, {encoding: \"utf-8\"}));\n}\n"]}
File without changes
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,gDAAsB;AACtB,oDAA0B","sourcesContent":["export * from \"jose2\";\nexport * from \"./getJwks\";\n"]}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,31 @@
1
+ import { ensureDirSync, existsSync, readFileSync, writeFileSync } from "fs-extra";
2
+ import { JWK, JWKS } from "jose2";
3
+ import { dirname } from "path";
4
+ export function generateJwks(options = {}) {
5
+ const { certificates } = options;
6
+ const keystore = new JWKS.KeyStore();
7
+ if (certificates) {
8
+ certificates.forEach(({ path, ...options }) => {
9
+ const content = readFileSync(path, { encoding: "utf-8" });
10
+ const isPrivate = content.includes("PRIVATE KEY");
11
+ if (!isPrivate) {
12
+ keystore.add(JWK.asKey(content, options));
13
+ }
14
+ });
15
+ }
16
+ else {
17
+ keystore.generateSync("RSA", 2048, { use: "sig" });
18
+ keystore.generateSync("EC", "P-256", { use: "sig", alg: "ES256" });
19
+ keystore.generateSync("OKP", "Ed25519", { use: "sig", alg: "EdDSA" });
20
+ }
21
+ return keystore.toJWKS(true);
22
+ }
23
+ export function getJwks(options) {
24
+ ensureDirSync(dirname(options.path));
25
+ if (!existsSync(options.path)) {
26
+ const keys = generateJwks(options);
27
+ writeFileSync(options.path, JSON.stringify(keys, null, 2));
28
+ }
29
+ return JSON.parse(readFileSync(options.path, { encoding: "utf-8" }));
30
+ }
31
+ //# sourceMappingURL=getJwks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getJwks.js","sourceRoot":"","sources":["../../src/getJwks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAC,MAAM,UAAU,CAAC;AAChF,OAAO,EAAC,GAAG,EAAE,IAAI,EAAgB,MAAM,OAAO,CAAC;AAC/C,OAAO,EAAC,OAAO,EAAC,MAAM,MAAM,CAAC;AAW7B,MAAM,U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AAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;KAC5D;IAED,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,EAAE,EAAC,QAAQ,EAAE,OAAO,EAAC,CAAC,CAAC,CAAC;AACrE,CAAC","sourcesContent":["import {ensureDirSync, existsSync, readFileSync, writeFileSync} from \"fs-extra\";\nimport {JWK, JWKS, KeyParameters} from \"jose2\";\nimport {dirname} from \"path\";\n\nexport interface JwksKeyParameters extends KeyParameters {\n path: string;\n}\n\nexport interface JwksOptions {\n path: string;\n certificates?: JwksKeyParameters[];\n}\n\nexport function generateJwks(options: Partial<JwksOptions> = {}) {\n const {certificates} = options;\n const keystore = new JWKS.KeyStore();\n\n if (certificates) {\n certificates.forEach(({path, ...options}) => {\n const content = readFileSync(path, {encoding: \"utf-8\"});\n const isPrivate = content.includes(\"PRIVATE KEY\");\n\n if (!isPrivate) {\n keystore.add(JWK.asKey(content, options));\n }\n });\n } else {\n keystore.generateSync(\"RSA\", 2048, {use: \"sig\"});\n keystore.generateSync(\"EC\", \"P-256\", {use: \"sig\", alg: \"ES256\"});\n keystore.generateSync(\"OKP\", \"Ed25519\", {use: \"sig\", alg: \"EdDSA\"});\n }\n\n return keystore.toJWKS(true);\n}\n\nexport function getJwks(options: JwksOptions) {\n ensureDirSync(dirname(options.path));\n\n if (!existsSync(options.path)) {\n const keys = generateJwks(options);\n writeFileSync(options.path, JSON.stringify(keys, null, 2));\n }\n\n return JSON.parse(readFileSync(options.path, {encoding: \"utf-8\"}));\n}\n"]}
@@ -0,0 +1,3 @@
1
+ export * from "jose2";
2
+ export * from "./getJwks.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,WAAW,CAAC","sourcesContent":["export * from \"jose2\";\nexport * from \"./getJwks\";\n"]}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
File without changes
File without changes
package/package.json CHANGED
@@ -1,19 +1,28 @@
1
1
  {
2
2
  "name": "@tsed/jwks",
3
- "version": "7.0.0-alpha.1",
3
+ "version": "7.0.0-beta.10",
4
4
  "description": "Utils to generate jwks pair keys",
5
5
  "source": "./src/index.ts",
6
- "main": "./lib/index.js",
7
- "typings": "./lib/index.d.ts",
8
- "private": false,
6
+ "main": "./lib/cjs/index.js",
7
+ "module": "./lib/esm/index.js",
8
+ "typings": "./lib/types/index.d.ts",
9
+ "exports": {
10
+ "types": "./lib/types/index.d.ts",
11
+ "import": "./lib/esm/index.js",
12
+ "require": "./lib/cjs/index.js",
13
+ "default": "./lib/esm/index.js"
14
+ },
9
15
  "scripts": {
10
- "build": "tsc --build tsconfig.compile.json",
16
+ "build": "yarn run build:esm && yarn run build:cjs",
17
+ "build:cjs": "tsc --build tsconfig.compile.json",
18
+ "build:esm": "tsc --build tsconfig.compile.esm.json",
19
+ "test": "cross-env NODE_ENV=test yarn jest --max-workers=2",
11
20
  "start": "ts-node -r tsconfig-paths/register test/app/index.ts"
12
21
  },
13
22
  "dependencies": {
14
- "fs-extra": "^9.0.1",
23
+ "fs-extra": "^10.0.1",
15
24
  "jose2": "npm:jose@^2.0.4",
16
- "tslib": "2.2.0"
25
+ "tslib": "2.3.1"
17
26
  },
18
27
  "devDependencies": {},
19
28
  "peerDependencies": {},
@@ -21,7 +30,7 @@
21
30
  "bugs": {
22
31
  "url": "https://github.com/tsedio/tsed/issues"
23
32
  },
24
- "homepage": "https://github.com/tsedio/tsed/tree/alpha/packages/security/jwks",
33
+ "homepage": "https://github.com/tsedio/tsed/tree/beta/packages/security/jwks",
25
34
  "author": "Romain Lenzotti",
26
35
  "license": "MIT"
27
36
  }
package/readme.md CHANGED
@@ -43,12 +43,12 @@ npm install --save @tsed/jwks
43
43
  import {generateJwks} from "./getJwks";
44
44
 
45
45
  // Generate only jwks
46
- const jwks = generateJwks()
46
+ const jwks = generateJwks();
47
47
 
48
48
  // Create keys.json file if not exists
49
49
  const jwks = getJwks({
50
50
  path: "path/to/keys.json"
51
- })
51
+ });
52
52
  ```
53
53
 
54
54
  Outputs:
@@ -81,16 +81,16 @@ const jwks = generateJwks({
81
81
  {path: "path/keys/sig.rsa.pub.pem", alg: "RS256", use: "sig", kid: "key-0"},
82
82
  {path: "path/keys/enc.rsa.pub.pem", alg: "RS256", use: "enc", kid: "key-1"}
83
83
  ]
84
- })
84
+ });
85
85
 
86
86
  // Create keys.json file if not exists
87
87
  const jwks = getJwks({
88
88
  path: "path/to/keys.json",
89
89
  certificates: [
90
90
  {path: "path/keys/sig.rsa.pub.pem", alg: "RS256", use: "sig", kid: "key-0"},
91
- {path: "path/keys/enc.rsa.pub.pem", alg: "RS256", use: "enc", kid: "key-1"},
91
+ {path: "path/keys/enc.rsa.pub.pem", alg: "RS256", use: "enc", kid: "key-1"}
92
92
  ]
93
- })
93
+ });
94
94
  ```
95
95
 
96
96
  ## Contributors
@@ -0,0 +1,12 @@
1
+ {
2
+ "extends": "./tsconfig.compile.json",
3
+ "compilerOptions": {
4
+ "baseUrl": ".",
5
+ "module": "ES2020",
6
+ "rootDir": "src",
7
+ "outDir": "./lib/esm",
8
+ "declaration": true,
9
+ "declarationDir": "./lib/types"
10
+ },
11
+ "exclude": ["node_modules", "test", "lib", "benchmark", "coverage", "spec", "**/*.benchmark.ts", "**/*.spec.ts", "keys", "jest.config.js"]
12
+ }
@@ -1 +0,0 @@
1
- {"version":3,"file":"getJwks.js","sourceRoot":"","sources":["../src/getJwks.ts"],"names":[],"mappings":";;;AAAA,uCAAgF;AAChF,iCAA+C;AAC/C,+BAA6B;AAW7B,SAAgB,YAAY,CAAC,UAAgC,EAAE;IAC7D,MAAM,EAAC,YAAY,EAAC,GAAG,OAAO,CAAC;IAC/B,MAAM,QAAQ,GAAG,IAAI,YAAI,CAAC,QAAQ,E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,KAAK,CAAC,uBAAY,CAAC,OAAO,CAAC,IAAI,EAAE,EAAC,QAAQ,EAAE,OAAO,EAAC,CAAC,CAAC,CAAC;AACrE,CAAC;AATD,0BASC","sourcesContent":["import {ensureDirSync, existsSync, readFileSync, writeFileSync} from \"fs-extra\";\nimport {JWK, JWKS, KeyParameters} from \"jose2\";\nimport {dirname} from \"path\";\n\nexport interface JwksKeyParameters extends KeyParameters {\n path: string;\n}\n\nexport interface JwksOptions {\n path: string;\n certificates?: JwksKeyParameters[];\n}\n\nexport function generateJwks(options: Partial<JwksOptions> = {}) {\n const {certificates} = options;\n const keystore = new JWKS.KeyStore();\n\n if (certificates) {\n certificates.forEach(({path, ...options}) => {\n const content = readFileSync(path, {encoding: \"utf-8\"});\n const isPrivate = content.includes(\"PRIVATE KEY\");\n\n if (!isPrivate) {\n keystore.add(JWK.asKey(content, options));\n }\n });\n } else {\n keystore.generateSync(\"RSA\", 2048, {use: \"sig\"});\n keystore.generateSync(\"EC\", \"P-256\", {use: \"sig\", alg: \"ES256\"});\n keystore.generateSync(\"OKP\", \"Ed25519\", {use: \"sig\", alg: \"EdDSA\"});\n }\n\n return keystore.toJWKS(true);\n}\n\nexport function getJwks(options: JwksOptions) {\n ensureDirSync(dirname(options.path));\n\n if (!existsSync(options.path)) {\n const keys = generateJwks(options);\n writeFileSync(options.path, JSON.stringify(keys, null, 2));\n }\n\n return JSON.parse(readFileSync(options.path, {encoding: \"utf-8\"}));\n}\n"]}
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,gDAAsB;AACtB,oDAA0B","sourcesContent":["export * from \"jose2\";\nexport * from \"./getJwks\";\n"]}