From 5c7d2656b6e5659a19c6cb3c4fed73e724fe2f6e Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Mon, 16 Aug 2021 22:53:31 +0200 Subject: [PATCH] feat: experimental Deno build & publish --- .github/workflows/publish.yml | 5 +- .github/workflows/test.yml | 23 ++++ .versionrc.json | 2 +- README.md | 2 +- package.json | 47 ++++---- src/.eslintrc.json | 41 ------- src/jwe/compact/decrypt.ts | 8 +- src/jwe/compact/encrypt.ts | 7 +- src/jwe/flattened/decrypt.ts | 8 +- src/jwe/flattened/encrypt.ts | 9 +- src/jwe/general/decrypt.ts | 9 +- src/jwk/embedded.ts | 10 +- src/jwk/from_key_like.ts | 7 +- src/jwk/parse.ts | 10 +- src/jwk/thumbprint.ts | 7 +- src/jwks/remote.ts | 28 +++-- src/jws/compact/sign.ts | 9 +- src/jws/compact/verify.ts | 8 +- src/jws/flattened/sign.ts | 9 +- src/jws/flattened/verify.ts | 8 +- src/jws/general/sign.ts | 8 +- src/jws/general/verify.ts | 9 +- src/jwt/decrypt.ts | 7 +- src/jwt/encrypt.ts | 9 +- src/jwt/sign.ts | 9 +- src/jwt/unsecured.ts | 9 +- src/jwt/verify.ts | 7 +- src/lib/buffer_utils.ts | 4 +- src/lib/check_key_type.ts | 2 +- src/lib/decrypt_key_management.ts | 5 +- src/lib/encrypt_key_management.ts | 4 +- src/lib/is_disjoint.ts | 3 - src/lib/jwt_claims_set.ts | 2 +- src/lib/jwt_producer.ts | 2 +- src/lib/secs.ts | 2 - src/lib/validate_crit.ts | 1 - src/runtime/browser/aesgcmkw.ts | 3 +- src/runtime/browser/aeskw.ts | 2 +- src/runtime/browser/decrypt.ts | 2 +- src/runtime/browser/digest.ts | 2 +- src/runtime/browser/encrypt.ts | 2 +- src/runtime/browser/fetch_jwks.ts | 2 +- src/runtime/browser/generate.ts | 2 +- src/runtime/browser/global.ts | 2 - src/runtime/browser/jwk_to_key.ts | 4 +- src/runtime/browser/key_to_jwk.ts | 5 +- src/runtime/browser/pbes2kw.ts | 2 +- src/runtime/browser/rsaes.ts | 2 +- src/runtime/browser/sign.ts | 2 +- src/runtime/browser/timing_safe_equal.ts | 2 +- src/runtime/browser/verify.ts | 2 +- src/runtime/browser/zlib.ts | 2 +- src/runtime/interfaces.d.ts | 4 +- src/runtime/node/aesgcmkw.ts | 3 +- src/runtime/node/aeskw.ts | 2 +- src/runtime/node/decrypt.ts | 6 +- src/runtime/node/digest.ts | 2 +- src/runtime/node/ecdhes.ts | 3 - src/runtime/node/encrypt.ts | 6 +- src/runtime/node/fetch_jwks.ts | 4 +- src/runtime/node/generate.ts | 1 - src/runtime/node/get_named_curve.ts | 1 - src/runtime/node/is_key_object.ts | 1 - src/runtime/node/jwk_to_key.ts | 4 +- src/runtime/node/key_to_jwk.ts | 4 +- src/runtime/node/pbes2kw.ts | 2 +- src/runtime/node/rsaes.ts | 2 +- src/runtime/node/sign.ts | 2 +- src/runtime/node/timing_safe_equal.ts | 2 +- src/runtime/node/verify.ts | 2 +- src/runtime/node/webcrypto.ts | 1 - src/runtime/node/zlib.ts | 2 +- src/types.d.ts | 143 +++++++++++------------ src/util/base64url.ts | 2 - src/util/decode_protected_header.ts | 7 +- src/util/errors.ts | 2 - src/util/generate_key_pair.ts | 7 +- src/util/generate_secret.ts | 7 +- test-browser/.eslintrc.json | 12 -- test-browser/jwe_asymmetric.js | 1 - test-deno/.prettierrc.json | 6 + test-deno/generate_keys.test.ts | 76 ++++++++++++ test-deno/generate_secrets.test.ts | 70 +++++++++++ test-deno/jwe_asymmetric.test.ts | 43 +++++++ test-deno/jwe_symmetric.test.ts | 139 ++++++++++++++++++++++ test-deno/jwks.test.ts | 23 ++++ test-deno/jws.test.ts | 86 ++++++++++++++ test-deno/keylike.test.ts | 58 +++++++++ test/.eslintrc.json | 7 -- test/jwe/compact.decrypt.test.mjs | 1 - test/jwe/compact.encrypt.test.mjs | 1 - test/jwe/cookbook.test.mjs | 2 - test/jwe/flattened.decrypt.test.mjs | 1 - test/jwe/flattened.encrypt.test.mjs | 1 - test/jwe/general.decrypt.test.mjs | 1 - test/jwe/smoke.test.mjs | 5 - test/jwk/embedded.test.mjs | 1 - test/jwks/remote.test.mjs | 1 - test/jws/compact.sign.test.mjs | 1 - test/jws/compact.verify.test.mjs | 1 - test/jws/cookbook.test.mjs | 1 - test/jws/flattened.sign.test.mjs | 1 - test/jws/flattened.verify.test.mjs | 1 - test/jws/general.test.mjs | 1 - test/jws/restrictions.test.mjs | 1 - test/jws/smoke.test.mjs | 5 - test/jwt/encrypt.test.mjs | 1 - test/jwt/sign.test.mjs | 1 - test/jwt/unsecured.test.mjs | 1 - tools/docs.postbump.js | 13 --- tools/postbump.js | 31 +++++ tools/typedoc-replace-version.js | 19 +++ 112 files changed, 877 insertions(+), 336 deletions(-) delete mode 100644 src/.eslintrc.json delete mode 100644 test-browser/.eslintrc.json create mode 100644 test-deno/.prettierrc.json create mode 100644 test-deno/generate_keys.test.ts create mode 100644 test-deno/generate_secrets.test.ts create mode 100644 test-deno/jwe_asymmetric.test.ts create mode 100644 test-deno/jwe_symmetric.test.ts create mode 100644 test-deno/jwks.test.ts create mode 100644 test-deno/jws.test.ts create mode 100644 test-deno/keylike.test.ts delete mode 100644 test/.eslintrc.json delete mode 100755 tools/docs.postbump.js create mode 100755 tools/postbump.js create mode 100644 tools/typedoc-replace-version.js diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 78feaa29eb..ecf0bf74f3 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -50,5 +50,8 @@ jobs: uses: actions/checkout@v2 with: fetch-depth: 0 - - run: git push origin $GITHUB_SHA:main - run: git push origin $GITHUB_SHA:v3.x + - run: git rm -r dist/**/* + - run: | + git commit -m "chore: cleanup after publish" + - run: git push origin HEAD:main diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9d9f3fccc5..2b4728d193 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -103,6 +103,28 @@ jobs: if: ${{ !startsWith(matrix.node-version, '14') && !startsWith(matrix.node-version, '12') }} - run: git reset HEAD --hard + test-deno: + needs: + - build + continue-on-error: true + + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - uses: denoland/setup-deno@v1 + with: + deno-version: v1.x + - name: Load cached dist + uses: actions/cache@v2 + id: dist + with: + path: dist + key: dist-${{ hashFiles('src/**/*.ts') }}-${{ hashFiles('tsconfig/*.json') }} + - name: Test Deno + run: npm run test-deno + - run: git reset HEAD --hard + test-electron: needs: - build @@ -188,6 +210,7 @@ jobs: - browserstack - test - test-electron + - test-deno runs-on: ubuntu-latest if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags') && github.repository == 'panva/jose' }} steps: diff --git a/.versionrc.json b/.versionrc.json index 54c1860b9b..6cde1ceb27 100644 --- a/.versionrc.json +++ b/.versionrc.json @@ -2,7 +2,7 @@ "commit-all": true, "scripts": { "prerelease": "npm run-script build-all", - "postbump": "node ./tools/docs.postbump.js", + "postbump": "node ./tools/postbump.js", "postchangelog": "sed -i '' -e 's/### \\[/## [/g' CHANGELOG.md" }, "types": [ diff --git a/README.md b/README.md index df04fe4975..e0e8c10954 100644 --- a/README.md +++ b/README.md @@ -133,7 +133,7 @@ Legend: | -- | -- | -- | | Node.js | LTS ^12.19.0 || ^14.15.0 | | | Electron | ^12.0.0 | see [1] | -| Deno | ✕ | needs to complete its [Web Cryptography API integration](https://github.com/denoland/deno/issues/1891) first | +| Deno | experimental | see Deno's [Web Cryptography API roadmap](https://github.com/denoland/deno/issues/11690) | | React Native | ✕ | has no available and usable crypto runtime | | IE | ✕ | implements old version of the Web Cryptography API specification | | Browsers | see [caniuse.com][caniuse] | | diff --git a/package.json b/package.json index d5a10b73c4..fee3790afb 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "decode", "decrypt", "detached", + "deno", "ec", "ecdsa", "eddsa", @@ -301,6 +302,16 @@ "require": "./dist/node/cjs/util/random.js" } }, + "typesVersions": { + "*": { + "webcrypto/*": [ + "./dist/types/*" + ], + "*": [ + "./dist/types/*" + ] + } + }, "files": [ "dist/**/package.json", "dist/**/*.js", @@ -316,16 +327,18 @@ "build-all": "run-s clear build:*", "build-fast-all": "run-s clear build-fast:*", "build-fast:browser": "npm run-script runtime-browser && npm run-script -s esbuild-find | xargs -0 esbuild --log-level=warning --target=es2018 --outdir=dist/browser --format=esm && echo '{\"type\": \"module\"}'> dist/browser/package.json", + "build-fast:deno": "npm run-script build:deno", "build-fast:node-cjs": "npm run-script runtime-node && npm run-script -s esbuild-find | xargs -0 esbuild --log-level=warning --platform=node --target=node12 --outdir=dist/node/cjs --format=cjs", "build-fast:node-esm": "npm run-script runtime-node && npm run-script -s esbuild-find | xargs -0 esbuild --log-level=warning --platform=node --target=node12 --outdir=dist/node/esm --format=esm && echo '{\"type\": \"module\"}'> dist/node/esm/package.json", "build-fast:node-webcrypto-cjs": "npm run-script runtime-node-webcrypto && npm run-script -s esbuild-find | xargs -0 esbuild --log-level=warning --platform=node --target=esnext --outdir=dist/node/webcrypto/cjs --format=cjs", "build-fast:node-webcrypto-esm": "npm run-script runtime-node-webcrypto && npm run-script -s esbuild-find | xargs -0 esbuild --log-level=warning --platform=node --target=esnext --outdir=dist/node/webcrypto/esm --format=esm && echo '{\"type\": \"module\"}'> dist/node/webcrypto/esm/package.json", - "build:browser": "run-s runtime-browser lint 'build -- -p ./tsconfig/browser.json' && echo '{\"type\": \"module\"}'> dist/browser/package.json", + "build:browser": "run-s runtime-browser 'build -- -p ./tsconfig/browser.json' && echo '{\"type\": \"module\"}'> dist/browser/package.json", + "build:deno": "npm run-script runtime-deno && find dist/deno -name '*.ts' -type f -print0 | xargs -0 sed -i '' -e \"s/\\.js'/.ts'/g\" -e \"s/\\.d'/.d.ts'/g\" && echo 'export class KeyObject extends CryptoKey {}' > dist/deno/types.d.ts && tail -n +5 src/types.d.ts >> dist/deno/types.d.ts", "build:types": "npm run-script build -- -p ./tsconfig/types.json && cd src && find . -name '*.d.ts' -maxdepth 2 -type f -exec gcp --parents \"{}\" ../dist/types \\; && cd .. && node ./tools/strip-dts-comments && run-s -s types:find | xargs -0 sed -i '' -e \"s/.js//g\"", - "build:node-cjs": "run-s runtime-node lint 'build -- -p ./tsconfig/node-cjs.json'", - "build:node-esm": "run-s runtime-node lint 'build -- -p ./tsconfig/node-esm.json' && echo '{\"type\": \"module\"}'> dist/node/esm/package.json", - "build:node-webcrypto-cjs": "run-s runtime-node-webcrypto lint 'build -- -p ./tsconfig/node-webcrypto-cjs.json'", - "build:node-webcrypto-esm": "run-s runtime-node-webcrypto lint 'build -- -p ./tsconfig/node-webcrypto-esm.json' && echo '{\"type\": \"module\"}'> dist/node/webcrypto/esm/package.json", + "build:node-cjs": "run-s runtime-node 'build -- -p ./tsconfig/node-cjs.json'", + "build:node-esm": "run-s runtime-node 'build -- -p ./tsconfig/node-esm.json' && echo '{\"type\": \"module\"}'> dist/node/esm/package.json", + "build:node-webcrypto-cjs": "run-s runtime-node-webcrypto 'build -- -p ./tsconfig/node-webcrypto-cjs.json'", + "build:node-webcrypto-esm": "run-s runtime-node-webcrypto 'build -- -p ./tsconfig/node-webcrypto-esm.json' && echo '{\"type\": \"module\"}'> dist/node/webcrypto/esm/package.json", "clear": "rm -rf dist", "coverage": "npm run-script runtime-node && c8 npm run-script test", "coverage-cryptokey": "npm run-script runtime-node && c8 npm run-script test-cryptokey", @@ -333,8 +346,8 @@ "docs": "run-s docs:*", "docs:generate": "typedoc --allReflectionsHaveOwnDocument --excludePrivate --excludeProtected --gitRevision main --readme none --plugin typedoc-plugin-markdown --out docs --excludeExternals --tsconfig ./tsconfig/browser.json --hideGenerator --hideBreadcrumbs src/types.d.ts src/jwt/*.ts src/jwe/**/*.ts src/jws/**/*.ts src/jwk/*.ts src/jwks/*.ts src/util/*.ts", "esbuild-find": "find src -type f -name '*.ts' -not -path '*/runtime/*/*' -not -name '*.d.ts' -print0", - "lint": "eslint --config ./src/.eslintrc.json ./src", "runtime-browser": "run-s runtime:clear runtime:browser:* runtime:refs", + "runtime-deno": "npm run-script runtime-browser && mkdir -p dist/deno && cp -r src/. dist/deno && rm -r dist/deno/runtime/browser dist/deno/runtime/node && rm dist/deno/.prettierrc.json", "runtime-node": "run-s runtime:clear runtime:node:* runtime:refs", "runtime-node-webcrypto": "run-s runtime:clear runtime:browser:* && cp ./src/runtime/node/webcrypto.ts ./src/runtime/ && cp ./src/runtime/node/fetch_jwks.ts ./src/runtime/ && cp ./src/runtime/node/base64url.ts ./src/runtime/ && cp ./src/runtime/node/zlib.ts ./src/runtime/ && run-s runtime:refs", "runtime:browser:copy": "cp ./src/runtime/browser/*.ts ./src/runtime", @@ -344,24 +357,19 @@ "runtime:node:copy": "cp ./src/runtime/node/*.ts ./src/runtime", "runtime:refs": "run-s -s runtime:find | xargs -0 sed -i '' -e \"s/'\\.\\.\\//'\\.\\//g\" -e \"s/'\\.\\/\\.\\./'../g\"", "test": "npm run-script test-cjs && ava", + "test-deno": "deno test --jobs --no-check --allow-net test-deno", "test-browser": "find test-browser -type f -name '*.js' -print0 | xargs -0 npx esbuild --log-level=warning --outdir=dist-browser-tests --bundle && karma start", "test-cjs": "rm -rf test/cjs && find test -type f -name '*.mjs' -print0 | xargs -0 npx esbuild --log-level=warning --target=esnext --outdir=test/cjs --format=cjs", "test-cryptokey": "CRYPTOKEY=true npm test", - "test-webcrypto": "WEBCRYPTO=true npm test" + "test-webcrypto": "WEBCRYPTO=true npm test", + "prettier": "npx prettier --write ./test ./src ./tools ./test-browser ./test-deno" }, "devDependencies": { "@types/node": "^16.6.2", - "@typescript-eslint/eslint-plugin": "^4.29.1", "ava": "^3.15.0", "bowser": "^2.11.0", "c8": "^7.8.0", "esbuild": "^0.12.21", - "eslint": "^7.32.0", - "eslint-config-airbnb-base": "14.2.1", - "eslint-config-airbnb-typescript": "^12.3.1", - "eslint-config-prettier": "^8.3.0", - "eslint-plugin-import": "^2.24.0", - "eslint-plugin-jsdoc": "^36.0.7", "glob": "^7.1.7", "karma": "^6.3.4", "karma-browserstack-launcher": "1.6.0", @@ -371,19 +379,10 @@ "npm-run-all": "^4.1.5", "prettier": "^2.3.2", "qunit": "^2.16.0", + "tar": "^6.1.10", "timekeeper": "^2.2.0", "typedoc": "^0.21.6", "typedoc-plugin-markdown": "^3.10.4", "typescript": "^4.3.5" - }, - "typesVersions": { - "*": { - "webcrypto/*": [ - "./dist/types/*" - ], - "*": [ - "./dist/types/*" - ] - } } } diff --git a/src/.eslintrc.json b/src/.eslintrc.json deleted file mode 100644 index f5443fb92f..0000000000 --- a/src/.eslintrc.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "plugins": ["jsdoc"], - "extends": ["airbnb-typescript/base", "prettier"], - "parserOptions": { - "project": "./tsconfig/browser.json" - }, - "rules": { - "no-underscore-dangle": "off", - "no-bitwise": "off", - "no-plusplus": "off", - "@typescript-eslint/indent": "off", - "@typescript-eslint/semi": "off", - "@typescript-eslint/no-extra-semi": "off", - "import/prefer-default-export": "off", - "jsdoc/check-access": 2, - "jsdoc/check-alignment": 2, - "jsdoc/check-indentation": 2, - "jsdoc/check-param-names": 2, - "jsdoc/check-property-names": 2, - "jsdoc/check-tag-names": 2, - "jsdoc/check-types": 2, - "jsdoc/empty-tags": 2, - "jsdoc/newline-after-description": 2, - "jsdoc/no-bad-blocks": 2, - "jsdoc/no-types": 2, - "jsdoc/require-description-complete-sentence": [1, { "abbreviations": ["e.g.", "i.e."] }], - "jsdoc/require-description": [2, { "checkConstructors": false }], - "jsdoc/require-hyphen-before-param-description": [2, "never"], - "jsdoc/require-param-description": 2, - "jsdoc/require-param-name": 2, - "jsdoc/require-param": 2, - "jsdoc/valid-types": 2 - }, - "ignorePatterns": [ - "src/runtime/*/*.ts", - "src/runtime/webcrypto.ts", - "src/runtime/global.ts", - "dist", - "src/runtime/*.d.ts" - ] -} diff --git a/src/jwe/compact/decrypt.ts b/src/jwe/compact/decrypt.ts index 7b54b37dd9..add51353c9 100644 --- a/src/jwe/compact/decrypt.ts +++ b/src/jwe/compact/decrypt.ts @@ -8,7 +8,7 @@ import type { GetKeyFunction, FlattenedJWE, CompactDecryptResult, -} from '../../types' +} from '../../types.d' /** * Interface for Compact JWE Decryption dynamic key resolution. @@ -33,6 +33,11 @@ export interface CompactDecryptGetKey extends GetKeyFunction { if (jwe instanceof Uint8Array) { - // eslint-disable-next-line no-param-reassign jwe = decoder.decode(jwe) } diff --git a/src/jwe/compact/encrypt.ts b/src/jwe/compact/encrypt.ts index cda4a6570b..6c37e035af 100644 --- a/src/jwe/compact/encrypt.ts +++ b/src/jwe/compact/encrypt.ts @@ -4,7 +4,7 @@ import type { JWEKeyManagementHeaderParameters, JWEHeaderParameters, EncryptOptions, -} from '../../types' +} from '../../types.d' /** * The CompactEncrypt class is a utility for creating Compact JWE strings. @@ -19,6 +19,11 @@ import type { * const { CompactEncrypt } = require('jose/jwe/compact/encrypt') * ``` * + * @example Deno import + * ```js + * import { CompactEncrypt } from 'https://deno.land/x/jose@VERSION/jwe/compact/encrypt.ts' + * ``` + * * @example Usage * ```js * const encoder = new TextEncoder() diff --git a/src/jwe/flattened/decrypt.ts b/src/jwe/flattened/decrypt.ts index 1f4111dc2a..9f4a72ad92 100644 --- a/src/jwe/flattened/decrypt.ts +++ b/src/jwe/flattened/decrypt.ts @@ -14,7 +14,7 @@ import type { JWEHeaderParameters, DecryptOptions, GetKeyFunction, -} from '../../types' +} from '../../types.d' import { encoder, decoder, concat } from '../../lib/buffer_utils.js' import cekFactory from '../../lib/cek.js' import random from '../../runtime/random.js' @@ -50,6 +50,11 @@ export interface FlattenedDecryptGetKey * const { flattenedDecrypt } = require('jose/jwe/flattened/decrypt') * ``` * + * @example Deno import + * ```js + * import { flattenedDecrypt } from 'https://deno.land/x/jose@VERSION/jwe/flattened/decrypt.ts' + * ``` + * * @example Usage * ```js * const decoder = new TextDecoder() @@ -180,7 +185,6 @@ async function flattenedDecrypt( } if (typeof key === 'function') { - // eslint-disable-next-line no-param-reassign key = await key(parsedProt, jwe) } diff --git a/src/jwe/flattened/encrypt.ts b/src/jwe/flattened/encrypt.ts index 32c7e41c83..dabcfd6892 100644 --- a/src/jwe/flattened/encrypt.ts +++ b/src/jwe/flattened/encrypt.ts @@ -4,8 +4,8 @@ import type { JWEHeaderParameters, JWEKeyManagementHeaderParameters, EncryptOptions, -} from '../../types' -import type { JWEKeyManagementHeaderResults } from '../../types.i' +} from '../../types.d' +import type { JWEKeyManagementHeaderResults } from '../../types.i.d' import ivFactory from '../../lib/iv.js' import { encode as base64url } from '../../runtime/base64url.js' import random from '../../runtime/random.js' @@ -35,6 +35,11 @@ const checkExtensions = validateCrit.bind(undefined, JWEInvalid, new Map()) * const { FlattenedEncrypt } = require('jose/jwe/flattened/encrypt') * ``` * + * @example Deno import + * ```js + * import { FlattenedEncrypt } from 'https://deno.land/x/jose@VERSION/jwe/flattened/encrypt.ts' + * ``` + * * @example Usage * ```js * const encoder = new TextEncoder() diff --git a/src/jwe/general/decrypt.ts b/src/jwe/general/decrypt.ts index 2b636d38d9..95cc31f81d 100644 --- a/src/jwe/general/decrypt.ts +++ b/src/jwe/general/decrypt.ts @@ -8,7 +8,7 @@ import type { FlattenedJWE, GeneralJWE, GeneralDecryptResult, -} from '../../types' +} from '../../types.d' import isObject from '../../lib/is_object.js' /** @@ -34,6 +34,11 @@ export interface GeneralDecryptGetKey extends GetKeyFunctionawait parseJwk(joseHeader.jwk!, joseHeader.alg!, true) if (key.type !== 'public') { diff --git a/src/jwk/from_key_like.ts b/src/jwk/from_key_like.ts index e2fd867820..d773843806 100644 --- a/src/jwk/from_key_like.ts +++ b/src/jwk/from_key_like.ts @@ -1,4 +1,4 @@ -import type { JWK, KeyLike } from '../types' +import type { JWK, KeyLike } from '../types.d' import asJWK from '../runtime/key_to_jwk.js' /** @@ -16,6 +16,11 @@ import asJWK from '../runtime/key_to_jwk.js' * const { fromKeyLike } = require('jose/jwk/from_key_like') * ``` * + * @example Deno import + * ```js + * import { fromKeyLike } from 'https://deno.land/x/jose@VERSION/jwk/from_key_like.ts' + * ``` + * * @example Usage * ```js * const privateJwk = await fromKeyLike(privateKey) diff --git a/src/jwk/parse.ts b/src/jwk/parse.ts index e6e103791e..dece991592 100644 --- a/src/jwk/parse.ts +++ b/src/jwk/parse.ts @@ -2,7 +2,7 @@ import { decode as base64url } from '../runtime/base64url.js' import asKeyObject from '../runtime/jwk_to_key.js' import { JOSENotSupported } from '../util/errors.js' import isObject from '../lib/is_object.js' -import type { JWK, KeyLike } from '../types' +import type { JWK, KeyLike } from '../types.d' /** * Converts a JWK to a runtime-specific key representation (KeyLike). Either @@ -26,6 +26,11 @@ import type { JWK, KeyLike } from '../types' * const { parseJwk } = require('jose/jwk/parse') * ``` * + * @example Deno import + * ```js + * import { parseJwk } from 'https://deno.land/x/jose@VERSION/jwk/parse.ts' + * ``` + * * @example Usage * ```js * const ecPublicKey = await parseJwk({ @@ -47,7 +52,6 @@ async function parseJwk(jwk: JWK, alg?: string, octAsKeyObject?: boolean): Promi throw new TypeError('JWK must be an object') } - // eslint-disable-next-line no-param-reassign alg ||= jwk.alg if (typeof alg !== 'string' || !alg) { @@ -60,7 +64,6 @@ async function parseJwk(jwk: JWK, alg?: string, octAsKeyObject?: boolean): Promi throw new TypeError('missing "k" (Key Value) Parameter value') } - // eslint-disable-next-line no-param-reassign, eqeqeq octAsKeyObject ??= jwk.ext !== true if (octAsKeyObject) { @@ -74,7 +77,6 @@ async function parseJwk(jwk: JWK, alg?: string, octAsKeyObject?: boolean): Promi 'RSA JWK "oth" (Other Primes Info) Parameter value is not supported', ) } - // eslint-disable-next-line no-fallthrough case 'EC': case 'OKP': return asKeyObject({ ...jwk, alg }) diff --git a/src/jwk/thumbprint.ts b/src/jwk/thumbprint.ts index 8bc94700c9..5cd28219f9 100644 --- a/src/jwk/thumbprint.ts +++ b/src/jwk/thumbprint.ts @@ -3,7 +3,7 @@ import { JOSENotSupported, JWKInvalid } from '../util/errors.js' import digest from '../runtime/digest.js' import { encode as base64url } from '../runtime/base64url.js' import { encoder } from '../lib/buffer_utils.js' -import type { JWK } from '../types' +import type { JWK } from '../types.d' import isObject from '../lib/is_object.js' const check = (value: unknown, description: string) => { @@ -30,6 +30,11 @@ const check = (value: unknown, description: string) => { * const { calculateThumbprint } = require('jose/jwk/thumbprint') * ``` * + * @example Deno import + * ```js + * import { calculateThumbprint } from 'https://deno.land/x/jose@VERSION/jwk/thumbprint.ts' + * ``` + * * @example Usage * ```js * const thumbprint = await calculateThumbprint({ diff --git a/src/jwks/remote.ts b/src/jwks/remote.ts index 69a4b8a5f7..c2a3d3561c 100644 --- a/src/jwks/remote.ts +++ b/src/jwks/remote.ts @@ -1,8 +1,10 @@ -import type { KeyObject } from 'crypto' -import type * as http from 'http' -import type * as https from 'https' - -import type { JWSHeaderParameters, JWK, FlattenedJWSInput, GetKeyFunction } from '../types' +import type { + KeyObject, + JWSHeaderParameters, + JWK, + FlattenedJWSInput, + GetKeyFunction, +} from '../types.d' import parseJWK from '../jwk/parse.js' import { JWKSInvalid, @@ -48,12 +50,15 @@ export interface RemoteJWKSetOptions { cooldownDuration?: number /** - * An instance of http.Agent or https.Agent to pass to the http.get or - * https.get method options. Use when behind an http(s) proxy. + * An instance of [http.Agent](https://nodejs.org/api/http.html#http_class_http_agent) + * or [https.Agent](https://nodejs.org/api/https.html#https_class_https_agent) to pass + * to the [http.get](https://nodejs.org/api/http.html#http_http_get_options_callback) + * or [https.get](https://nodejs.org/api/https.html#https_https_get_options_callback) + * method's options. Use when behind an http(s) proxy. * This is a Node.js runtime specific option, it is ignored * when used outside of Node.js runtime. */ - agent?: https.Agent | http.Agent + agent?: any } function isJWKLike(key: unknown): key is JWK { @@ -202,7 +207,7 @@ class RemoteJWKSet { this._cooldownStarted = Date.now() this._pendingFetch = undefined }) - .catch((err) => { + .catch((err: Error) => { this._pendingFetch = undefined throw err }) @@ -228,6 +233,11 @@ class RemoteJWKSet { * const { createRemoteJWKSet } = require('jose/jwks/remote') * ``` * + * @example Deno import + * ```js + * import { createRemoteJWKSet } from 'https://deno.land/x/jose@VERSION/jwks/remote.ts' + * ``` + * * @example Usage * ```js * import { jwtVerify } from 'jose/jwt/verify' diff --git a/src/jws/compact/sign.ts b/src/jws/compact/sign.ts index fa55f0efbe..e2221eb59d 100644 --- a/src/jws/compact/sign.ts +++ b/src/jws/compact/sign.ts @@ -1,7 +1,5 @@ -/* eslint-disable no-underscore-dangle */ - import FlattenedSign from '../flattened/sign.js' -import type { JWSHeaderParameters, KeyLike, SignOptions } from '../../types' +import type { JWSHeaderParameters, KeyLike, SignOptions } from '../../types.d' /** * The CompactSign class is a utility for creating Compact JWS strings. @@ -16,6 +14,11 @@ import type { JWSHeaderParameters, KeyLike, SignOptions } from '../../types' * const { CompactSign } = require('jose/jws/compact/sign') * ``` * + * @example Deno import + * ```js + * import { CompactSign } from 'https://deno.land/x/jose@VERSION/jws/compact/sign.ts' + * ``` + * * @example Usage * ```js * const encoder = new TextEncoder() diff --git a/src/jws/compact/verify.ts b/src/jws/compact/verify.ts index 37089f4312..16d7dd1a81 100644 --- a/src/jws/compact/verify.ts +++ b/src/jws/compact/verify.ts @@ -8,7 +8,7 @@ import type { JWSHeaderParameters, KeyLike, VerifyOptions, -} from '../../types' +} from '../../types.d' /** * Interface for Compact JWS Verification dynamic key resolution. @@ -37,6 +37,11 @@ export interface CompactVerifyGetKey * const { compactVerify } = require('jose/jws/compact/verify') * ``` * + * @example Deno import + * ```js + * import { compactVerify } from 'https://deno.land/x/jose@VERSION/jws/compact/verify.ts' + * ``` + * * @example Usage * ```js * const decoder = new TextDecoder() @@ -54,7 +59,6 @@ async function compactVerify( options?: VerifyOptions, ): Promise { if (jws instanceof Uint8Array) { - // eslint-disable-next-line no-param-reassign jws = decoder.decode(jws) } diff --git a/src/jws/flattened/sign.ts b/src/jws/flattened/sign.ts index 661b43a252..107795a1c4 100644 --- a/src/jws/flattened/sign.ts +++ b/src/jws/flattened/sign.ts @@ -1,12 +1,10 @@ -/* eslint-disable no-underscore-dangle */ - import isDisjoint from '../../lib/is_disjoint.js' import { JWSInvalid } from '../../util/errors.js' import { encoder, decoder, concat } from '../../lib/buffer_utils.js' import { encode as base64url } from '../../runtime/base64url.js' import sign from '../../runtime/sign.js' -import type { KeyLike, FlattenedJWS, JWSHeaderParameters, SignOptions } from '../../types' +import type { KeyLike, FlattenedJWS, JWSHeaderParameters, SignOptions } from '../../types.d' import checkKeyType from '../../lib/check_key_type.js' import validateCrit from '../../lib/validate_crit.js' @@ -25,6 +23,11 @@ const checkExtensions = validateCrit.bind(undefined, JWSInvalid, new Map([['b64' * const { FlattenedSign } = require('jose/jws/flattened/sign') * ``` * + * @example Deno import + * ```js + * import { FlattenedSign } from 'https://deno.land/x/jose@VERSION/jws/flattened/sign.ts' + * ``` + * * @example Usage * ```js * const encoder = new TextEncoder() diff --git a/src/jws/flattened/verify.ts b/src/jws/flattened/verify.ts index e82abd1623..0b0fac5685 100644 --- a/src/jws/flattened/verify.ts +++ b/src/jws/flattened/verify.ts @@ -16,7 +16,7 @@ import type { JWSHeaderParameters, VerifyOptions, GetKeyFunction, -} from '../../types' +} from '../../types.d' const checkExtensions = validateCrit.bind(undefined, JWSInvalid, new Map([['b64', true]])) const checkAlgOption = validateAlgorithms.bind(undefined, 'algorithms') @@ -48,6 +48,11 @@ export interface FlattenedVerifyGetKey * const { flattenedVerify } = require('jose/jws/flattened/verify') * ``` * + * @example Deno import + * ```js + * import { flattenedVerify } from 'https://deno.land/x/jose@VERSION/jws/flattened/verify.ts' + * ``` + * * @example Usage * ```js * const decoder = new TextDecoder() @@ -145,7 +150,6 @@ async function flattenedVerify( } if (typeof key === 'function') { - // eslint-disable-next-line no-param-reassign key = await key(parsedProt, jws) } diff --git a/src/jws/general/sign.ts b/src/jws/general/sign.ts index d93f8aa5f3..fdf312f90a 100644 --- a/src/jws/general/sign.ts +++ b/src/jws/general/sign.ts @@ -1,8 +1,7 @@ -/* eslint-disable max-classes-per-file */ import FlattenedSign from '../flattened/sign.js' import { JWSInvalid } from '../../util/errors.js' -import type { KeyLike, GeneralJWS, JWSHeaderParameters, SignOptions } from '../../types' +import type { KeyLike, GeneralJWS, JWSHeaderParameters, SignOptions } from '../../types.d' export interface Signature { /** @@ -76,6 +75,11 @@ class IndividualSignature implements Signature { * const { GeneralSign } = require('jose/jws/general/sign') * ``` * + * @example Deno import + * ```js + * import { GeneralSign } from 'https://deno.land/x/jose@VERSION/jws/general/sign.ts' + * ``` + * * @example Usage * ```js * const encoder = new TextEncoder() diff --git a/src/jws/general/verify.ts b/src/jws/general/verify.ts index 4ee1122d25..900f53157a 100644 --- a/src/jws/general/verify.ts +++ b/src/jws/general/verify.ts @@ -7,7 +7,7 @@ import type { JWSHeaderParameters, KeyLike, VerifyOptions, -} from '../../types' +} from '../../types.d' import { JWSInvalid, JWSSignatureVerificationFailed } from '../../util/errors.js' import isObject from '../../lib/is_object.js' @@ -38,6 +38,11 @@ export interface GeneralVerifyGetKey * const { generalVerify } = require('jose/jws/general/verify') * ``` * + * @example Deno import + * ```js + * import { generalVerify } from 'https://deno.land/x/jose@VERSION/jws/general/verify.ts' + * ``` + * * @example Usage * ```js * const decoder = new TextDecoder() @@ -70,10 +75,8 @@ async function generalVerify( throw new JWSInvalid('JWS Signatures missing or incorrect type') } - // eslint-disable-next-line no-restricted-syntax for (const signature of jws.signatures) { try { - // eslint-disable-next-line no-await-in-loop return await verify( { header: signature.header, diff --git a/src/jwt/decrypt.ts b/src/jwt/decrypt.ts index aa0233262e..d2d4ed0a98 100644 --- a/src/jwt/decrypt.ts +++ b/src/jwt/decrypt.ts @@ -8,7 +8,7 @@ import type { JWEHeaderParameters, FlattenedJWE, JWTDecryptResult, -} from '../types' +} from '../types.d' import jwtPayload from '../lib/jwt_claims_set.js' import { JWTClaimValidationFailed } from '../util/errors.js' @@ -40,6 +40,11 @@ export interface JWTDecryptGetKey extends GetKeyFunction) => { const sources = headers.filter(Boolean) diff --git a/src/lib/jwt_claims_set.ts b/src/lib/jwt_claims_set.ts index 4d9349381d..2cffa4ddec 100644 --- a/src/lib/jwt_claims_set.ts +++ b/src/lib/jwt_claims_set.ts @@ -3,7 +3,7 @@ import type { JWTClaimVerificationOptions, JWEHeaderParameters, JWSHeaderParameters, -} from '../types' +} from '../types.d' import { JWTClaimValidationFailed, JWTExpired, JWTInvalid } from '../util/errors.js' import { decoder } from './buffer_utils.js' import epoch from './epoch.js' diff --git a/src/lib/jwt_producer.ts b/src/lib/jwt_producer.ts index 2b672437d3..83fdf4b260 100644 --- a/src/lib/jwt_producer.ts +++ b/src/lib/jwt_producer.ts @@ -1,4 +1,4 @@ -import type { JWTPayload } from '../types' +import type { JWTPayload } from '../types.d' import epoch from './epoch.js' import isObject from './is_object.js' import secs from './secs.js' diff --git a/src/lib/secs.ts b/src/lib/secs.ts index c9aa8d0726..8d9f07f7de 100644 --- a/src/lib/secs.ts +++ b/src/lib/secs.ts @@ -7,7 +7,6 @@ const year = day * 365.25 const REGEX = /^(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)$/i -// eslint-disable-next-line consistent-return export default (str: string): number => { const matched = REGEX.exec(str) @@ -18,7 +17,6 @@ export default (str: string): number => { const value = parseFloat(matched[1]) const unit = matched[2].toLowerCase() - // eslint-disable-next-line default-case switch (unit) { case 'sec': case 'secs': diff --git a/src/lib/validate_crit.ts b/src/lib/validate_crit.ts index b8941a6caa..1467af2f7f 100644 --- a/src/lib/validate_crit.ts +++ b/src/lib/validate_crit.ts @@ -38,7 +38,6 @@ function validateCrit( recognized = recognizedDefault } - // eslint-disable-next-line no-restricted-syntax for (const parameter of protectedHeader.crit) { if (!recognized.has(parameter)) { throw new JOSENotSupported(`Extension Header Parameter "${parameter}" is not recognized`) diff --git a/src/runtime/browser/aesgcmkw.ts b/src/runtime/browser/aesgcmkw.ts index ae028120b1..f3e6a68982 100644 --- a/src/runtime/browser/aesgcmkw.ts +++ b/src/runtime/browser/aesgcmkw.ts @@ -1,4 +1,4 @@ -import type { AesGcmKwUnwrapFunction, AesGcmKwWrapFunction } from '../interfaces' +import type { AesGcmKwUnwrapFunction, AesGcmKwWrapFunction } from '../interfaces.d' import encrypt from './encrypt.js' import decrypt from './decrypt.js' import ivFactory from '../../lib/iv.js' @@ -14,7 +14,6 @@ export const wrap: AesGcmKwWrapFunction = async ( iv?: Uint8Array, ) => { const jweAlgorithm = alg.substr(0, 7) - // eslint-disable-next-line no-param-reassign iv ||= generateIv(jweAlgorithm) const { ciphertext: encryptedKey, tag } = await encrypt( diff --git a/src/runtime/browser/aeskw.ts b/src/runtime/browser/aeskw.ts index 6554f94163..ea2380bd3a 100644 --- a/src/runtime/browser/aeskw.ts +++ b/src/runtime/browser/aeskw.ts @@ -1,4 +1,4 @@ -import type { AesKwUnwrapFunction, AesKwWrapFunction } from '../interfaces' +import type { AesKwUnwrapFunction, AesKwWrapFunction } from '../interfaces.d' import bogusWebCrypto from './bogus.js' import crypto, { isCryptoKey } from './webcrypto.js' import invalidKeyInput from './invalid_key_input.js' diff --git a/src/runtime/browser/decrypt.ts b/src/runtime/browser/decrypt.ts index 2ce437266a..337ecc7e9e 100644 --- a/src/runtime/browser/decrypt.ts +++ b/src/runtime/browser/decrypt.ts @@ -1,6 +1,6 @@ import { concat, uint64be } from '../../lib/buffer_utils.js' -import type { DecryptFunction } from '../interfaces' +import type { DecryptFunction } from '../interfaces.d' import checkIvLength from '../../lib/check_iv_length.js' import checkCekLength from './check_cek_length.js' import timingSafeEqual from './timing_safe_equal.js' diff --git a/src/runtime/browser/digest.ts b/src/runtime/browser/digest.ts index 06ac32b7a7..cf735dd065 100644 --- a/src/runtime/browser/digest.ts +++ b/src/runtime/browser/digest.ts @@ -1,5 +1,5 @@ import crypto from './webcrypto.js' -import type { DigestFunction } from '../interfaces' +import type { DigestFunction } from '../interfaces.d' const digest: DigestFunction = async ( algorithm: 'sha256' | 'sha384' | 'sha512', diff --git a/src/runtime/browser/encrypt.ts b/src/runtime/browser/encrypt.ts index 88d9a50e65..bf157087dc 100644 --- a/src/runtime/browser/encrypt.ts +++ b/src/runtime/browser/encrypt.ts @@ -1,5 +1,5 @@ import { concat, uint64be } from '../../lib/buffer_utils.js' -import type { EncryptFunction } from '../interfaces' +import type { EncryptFunction } from '../interfaces.d' import checkIvLength from '../../lib/check_iv_length.js' import checkCekLength from './check_cek_length.js' import crypto, { isCryptoKey } from './webcrypto.js' diff --git a/src/runtime/browser/fetch_jwks.ts b/src/runtime/browser/fetch_jwks.ts index ef3f6c79c7..09f72a1fee 100644 --- a/src/runtime/browser/fetch_jwks.ts +++ b/src/runtime/browser/fetch_jwks.ts @@ -1,4 +1,4 @@ -import type { FetchFunction } from '../interfaces' +import type { FetchFunction } from '../interfaces.d' import { JOSEError } from '../../util/errors.js' import globalThis from './global.js' diff --git a/src/runtime/browser/generate.ts b/src/runtime/browser/generate.ts index d08e70f049..c63eb193eb 100644 --- a/src/runtime/browser/generate.ts +++ b/src/runtime/browser/generate.ts @@ -43,7 +43,7 @@ export async function generateSecret(alg: string, options?: GenerateSecretOption } return >( - crypto.subtle.generateKey(algorithm, options?.extractable ?? false, keyUsages) + (crypto.subtle.generateKey(algorithm, options?.extractable ?? false, keyUsages)) ) } diff --git a/src/runtime/browser/global.ts b/src/runtime/browser/global.ts index 8f9f21b5ee..ba85627857 100644 --- a/src/runtime/browser/global.ts +++ b/src/runtime/browser/global.ts @@ -1,5 +1,3 @@ -/* eslint-disable no-restricted-globals */ - function getGlobal() { if (typeof globalThis !== 'undefined') return globalThis if (typeof self !== 'undefined') return self diff --git a/src/runtime/browser/jwk_to_key.ts b/src/runtime/browser/jwk_to_key.ts index d08d5f0b17..7b6970a6af 100644 --- a/src/runtime/browser/jwk_to_key.ts +++ b/src/runtime/browser/jwk_to_key.ts @@ -1,7 +1,7 @@ import crypto from './webcrypto.js' -import type { JWKParseFunction } from '../interfaces' +import type { JWKParseFunction } from '../interfaces.d' import { JOSENotSupported } from '../../util/errors.js' -import type { JWK } from '../../types' +import type { JWK } from '../../types.d' import { decode as base64url } from './base64url.js' function subtleMapping(jwk: JWK): { diff --git a/src/runtime/browser/key_to_jwk.ts b/src/runtime/browser/key_to_jwk.ts index cbc3c4237d..cc877e8e5f 100644 --- a/src/runtime/browser/key_to_jwk.ts +++ b/src/runtime/browser/key_to_jwk.ts @@ -1,6 +1,6 @@ import crypto, { isCryptoKey } from './webcrypto.js' -import type { JWKConvertFunction } from '../interfaces' -import type { JWK } from '../../types' +import type { JWKConvertFunction } from '../interfaces.d' +import type { JWK } from '../../types.d' import invalidKeyInput from './invalid_key_input.js' import { encode as base64url } from './base64url.js' @@ -17,7 +17,6 @@ const keyToJWK: JWKConvertFunction = async (key: unknown): Promise => { if (!key.extractable) { throw new TypeError('non-extractable CryptoKey cannot be exported as a JWK') } - // eslint-disable-next-line @typescript-eslint/naming-convention const { ext, key_ops, alg, use, ...jwk } = await crypto.subtle.exportKey('jwk', key) return jwk diff --git a/src/runtime/browser/pbes2kw.ts b/src/runtime/browser/pbes2kw.ts index f24bf15d7a..544837e77d 100644 --- a/src/runtime/browser/pbes2kw.ts +++ b/src/runtime/browser/pbes2kw.ts @@ -1,4 +1,4 @@ -import type { Pbes2KWDecryptFunction, Pbes2KWEncryptFunction } from '../interfaces' +import type { Pbes2KWDecryptFunction, Pbes2KWEncryptFunction } from '../interfaces.d' import random from './random.js' import { p2s as concatSalt } from '../../lib/buffer_utils.js' import { encode as base64url } from './base64url.js' diff --git a/src/runtime/browser/rsaes.ts b/src/runtime/browser/rsaes.ts index 17a1f86dbc..ecb5ef619e 100644 --- a/src/runtime/browser/rsaes.ts +++ b/src/runtime/browser/rsaes.ts @@ -1,4 +1,4 @@ -import type { RsaEsDecryptFunction, RsaEsEncryptFunction } from '../interfaces' +import type { RsaEsDecryptFunction, RsaEsEncryptFunction } from '../interfaces.d' import subtleAlgorithm from './subtle_rsaes.js' import bogusWebCrypto from './bogus.js' import crypto, { isCryptoKey } from './webcrypto.js' diff --git a/src/runtime/browser/sign.ts b/src/runtime/browser/sign.ts index b646a59180..f1535d5b38 100644 --- a/src/runtime/browser/sign.ts +++ b/src/runtime/browser/sign.ts @@ -1,4 +1,4 @@ -import type { SignFunction } from '../interfaces' +import type { SignFunction } from '../interfaces.d' import subtleAlgorithm from './subtle_dsa.js' import crypto from './webcrypto.js' import checkKeyLength from './check_key_length.js' diff --git a/src/runtime/browser/timing_safe_equal.ts b/src/runtime/browser/timing_safe_equal.ts index efd18494cc..7b06568c63 100644 --- a/src/runtime/browser/timing_safe_equal.ts +++ b/src/runtime/browser/timing_safe_equal.ts @@ -1,4 +1,4 @@ -import type { TimingSafeEqual } from '../interfaces' +import type { TimingSafeEqual } from '../interfaces.d' const timingSafeEqual: TimingSafeEqual = (a, b) => { if (!(a instanceof Uint8Array)) { diff --git a/src/runtime/browser/verify.ts b/src/runtime/browser/verify.ts index bd016b1e9b..a7f5892bfc 100644 --- a/src/runtime/browser/verify.ts +++ b/src/runtime/browser/verify.ts @@ -1,4 +1,4 @@ -import type { VerifyFunction } from '../interfaces' +import type { VerifyFunction } from '../interfaces.d' import subtleAlgorithm from './subtle_dsa.js' import crypto from './webcrypto.js' import checkKeyLength from './check_key_length.js' diff --git a/src/runtime/browser/zlib.ts b/src/runtime/browser/zlib.ts index f2c05e59d3..ae2a4e4a5f 100644 --- a/src/runtime/browser/zlib.ts +++ b/src/runtime/browser/zlib.ts @@ -1,5 +1,5 @@ import { JOSENotSupported } from '../../util/errors.js' -import type { InflateFunction, DeflateFunction } from '../../types' +import type { InflateFunction, DeflateFunction } from '../../types.d' export const inflate: InflateFunction = async () => { throw new JOSENotSupported( diff --git a/src/runtime/interfaces.d.ts b/src/runtime/interfaces.d.ts index 89a46c25fb..15b96e62b1 100644 --- a/src/runtime/interfaces.d.ts +++ b/src/runtime/interfaces.d.ts @@ -1,5 +1,5 @@ -import type { JWK, KeyLike } from '../types' -import type { AsyncOrSync } from '../types.i' +import type { JWK, KeyLike } from '../types.d' +import type { AsyncOrSync } from '../types.i.d' export interface TimingSafeEqual { (a: Uint8Array, b: Uint8Array): boolean diff --git a/src/runtime/node/aesgcmkw.ts b/src/runtime/node/aesgcmkw.ts index 44750b78e5..92848a50de 100644 --- a/src/runtime/node/aesgcmkw.ts +++ b/src/runtime/node/aesgcmkw.ts @@ -1,4 +1,4 @@ -import type { AesGcmKwWrapFunction, AesGcmKwUnwrapFunction } from '../interfaces' +import type { AesGcmKwWrapFunction, AesGcmKwUnwrapFunction } from '../interfaces.d' import encrypt from './encrypt.js' import decrypt from './decrypt.js' import ivFactory from '../../lib/iv.js' @@ -14,7 +14,6 @@ export const wrap: AesGcmKwWrapFunction = async ( iv?: Uint8Array, ) => { const jweAlgorithm = alg.substr(0, 7) - // eslint-disable-next-line no-param-reassign iv ||= generateIv(jweAlgorithm) const { ciphertext: encryptedKey, tag } = await encrypt( diff --git a/src/runtime/node/aeskw.ts b/src/runtime/node/aeskw.ts index e734a9c57e..c4229a0ca4 100644 --- a/src/runtime/node/aeskw.ts +++ b/src/runtime/node/aeskw.ts @@ -1,6 +1,6 @@ import { KeyObject, createDecipheriv, createCipheriv } from 'crypto' import { JOSENotSupported } from '../../util/errors.js' -import type { AesKwUnwrapFunction, AesKwWrapFunction } from '../interfaces' +import type { AesKwUnwrapFunction, AesKwWrapFunction } from '../interfaces.d' import { concat } from '../../lib/buffer_utils.js' import getSecretKey from './secret_key.js' import { isCryptoKey, getKeyObject } from './webcrypto.js' diff --git a/src/runtime/node/decrypt.ts b/src/runtime/node/decrypt.ts index c18df7a2f8..9220df8dc1 100644 --- a/src/runtime/node/decrypt.ts +++ b/src/runtime/node/decrypt.ts @@ -1,7 +1,7 @@ import { KeyObject, createDecipheriv } from 'crypto' import type { CipherGCMTypes } from 'crypto' -import type { DecryptFunction } from '../interfaces' +import type { DecryptFunction } from '../interfaces.d' import checkIvLength from '../../lib/check_iv_length.js' import checkCekLength from './check_cek_length.js' import { concat } from '../../lib/buffer_utils.js' @@ -9,7 +9,7 @@ import { JOSENotSupported, JWEDecryptionFailed } from '../../util/errors.js' import timingSafeEqual from './timing_safe_equal.js' import cbcTag from './cbc_tag.js' import { isCryptoKey, getKeyObject } from './webcrypto.js' -import type { KeyLike } from '../../types' +import type { KeyLike } from '../../types.d' import isKeyObject from './is_key_object.js' import invalidKeyInput from './invalid_key_input.js' import supported from './ciphers.js' @@ -25,7 +25,6 @@ async function cbcDecrypt( const keySize = parseInt(enc.substr(1, 3), 10) if (isKeyObject(cek)) { - // eslint-disable-next-line no-param-reassign cek = cek.export() } @@ -100,7 +99,6 @@ const decrypt: DecryptFunction = async ( ) => { let key: KeyLike if (isCryptoKey(cek)) { - // eslint-disable-next-line no-param-reassign key = getKeyObject(cek, enc, new Set(['decrypt'])) } else if (cek instanceof Uint8Array || isKeyObject(cek)) { key = cek diff --git a/src/runtime/node/digest.ts b/src/runtime/node/digest.ts index b267f2e3c5..883df3a26c 100644 --- a/src/runtime/node/digest.ts +++ b/src/runtime/node/digest.ts @@ -1,5 +1,5 @@ import { createHash } from 'crypto' -import type { DigestFunction } from '../interfaces' +import type { DigestFunction } from '../interfaces.d' const digest: DigestFunction = ( algorithm: 'sha256' | 'sha384' | 'sha512', diff --git a/src/runtime/node/ecdhes.ts b/src/runtime/node/ecdhes.ts index 31210bb138..fb071408e2 100644 --- a/src/runtime/node/ecdhes.ts +++ b/src/runtime/node/ecdhes.ts @@ -32,7 +32,6 @@ export const deriveKey: EcdhESDeriveKeyFunction = async ( ) if (isCryptoKey(publicKey)) { - // eslint-disable-next-line no-param-reassign publicKey = getKeyObject(publicKey, 'ECDH-ES') } if (!isKeyObject(publicKey)) { @@ -40,7 +39,6 @@ export const deriveKey: EcdhESDeriveKeyFunction = async ( } if (isCryptoKey(privateKey)) { - // eslint-disable-next-line no-param-reassign privateKey = getKeyObject(privateKey, 'ECDH-ES', new Set(['deriveBits', 'deriveKey'])) } if (!isKeyObject(privateKey)) { @@ -53,7 +51,6 @@ export const deriveKey: EcdhESDeriveKeyFunction = async ( export const generateEpk: GenerateEpkFunction = async (key: unknown) => { if (isCryptoKey(key)) { - // eslint-disable-next-line no-param-reassign key = getKeyObject(key) } if (!isKeyObject(key)) { diff --git a/src/runtime/node/encrypt.ts b/src/runtime/node/encrypt.ts index b1f4fc9f2c..8bc8af78ad 100644 --- a/src/runtime/node/encrypt.ts +++ b/src/runtime/node/encrypt.ts @@ -1,12 +1,12 @@ import { KeyObject, createCipheriv } from 'crypto' import type { CipherGCMTypes } from 'crypto' -import type { EncryptFunction } from '../interfaces' +import type { EncryptFunction } from '../interfaces.d' import checkIvLength from '../../lib/check_iv_length.js' import checkCekLength from './check_cek_length.js' import { concat } from '../../lib/buffer_utils.js' import cbcTag from './cbc_tag.js' -import type { KeyLike } from '../../types' +import type { KeyLike } from '../../types.d' import { isCryptoKey, getKeyObject } from './webcrypto.js' import isKeyObject from './is_key_object.js' import invalidKeyInput from './invalid_key_input.js' @@ -23,7 +23,6 @@ async function cbcEncrypt( const keySize = parseInt(enc.substr(1, 3), 10) if (isKeyObject(cek)) { - // eslint-disable-next-line no-param-reassign cek = cek.export() } @@ -77,7 +76,6 @@ const encrypt: EncryptFunction = async ( ) => { let key: KeyLike if (isCryptoKey(cek)) { - // eslint-disable-next-line no-param-reassign key = getKeyObject(cek, enc, new Set(['encrypt'])) } else if (cek instanceof Uint8Array || isKeyObject(cek)) { key = cek diff --git a/src/runtime/node/fetch_jwks.ts b/src/runtime/node/fetch_jwks.ts index 1b3d27b390..43c25782d4 100644 --- a/src/runtime/node/fetch_jwks.ts +++ b/src/runtime/node/fetch_jwks.ts @@ -4,7 +4,7 @@ import { once } from 'events' import type { ClientRequest, IncomingMessage } from 'http' import type { RequestOptions } from 'https' -import type { FetchFunction } from '../interfaces' +import type { FetchFunction } from '../interfaces.d' import { JOSEError } from '../../util/errors.js' import { concat, decoder } from '../../lib/buffer_utils.js' @@ -30,7 +30,6 @@ const fetchJwks: FetchFunction = async ( timeout, }) - // eslint-disable-next-line @typescript-eslint/keyword-spacing const [response] = <[IncomingMessage]>await once(req, 'response') if (response.statusCode !== 200) { @@ -38,7 +37,6 @@ const fetchJwks: FetchFunction = async ( } const parts = [] - // eslint-disable-next-line no-restricted-syntax for await (const part of response) { parts.push(part) } diff --git a/src/runtime/node/generate.ts b/src/runtime/node/generate.ts index 7fec0000f5..0b3c488cf1 100644 --- a/src/runtime/node/generate.ts +++ b/src/runtime/node/generate.ts @@ -10,7 +10,6 @@ import type { GenerateSecretOptions } from '../../util/generate_secret.js' const generate = promisify(generateKeyPairCb) // @ts-expect-error -// eslint-disable-next-line @typescript-eslint/no-unused-vars export async function generateSecret(alg: string, options?: GenerateSecretOptions) { let length: number switch (alg) { diff --git a/src/runtime/node/get_named_curve.ts b/src/runtime/node/get_named_curve.ts index f7064eee7b..e3644c3d2d 100644 --- a/src/runtime/node/get_named_curve.ts +++ b/src/runtime/node/get_named_curve.ts @@ -28,7 +28,6 @@ const namedCurveToJOSE = (namedCurve: string) => { const getNamedCurve = (key: unknown, raw?: boolean): string => { if (isCryptoKey(key)) { - // eslint-disable-next-line no-param-reassign key = getKeyObject(key) } if (!isKeyObject(key)) { diff --git a/src/runtime/node/is_key_object.ts b/src/runtime/node/is_key_object.ts index 75963f03a7..567eb87594 100644 --- a/src/runtime/node/is_key_object.ts +++ b/src/runtime/node/is_key_object.ts @@ -1,7 +1,6 @@ import { KeyObject } from 'crypto' import * as util from 'util' -// eslint-disable-next-line import/no-mutable-exports let impl: (obj: unknown) => obj is KeyObject if (util.types.isKeyObject) { diff --git a/src/runtime/node/jwk_to_key.ts b/src/runtime/node/jwk_to_key.ts index 4dd9c1fe6e..795cba3082 100644 --- a/src/runtime/node/jwk_to_key.ts +++ b/src/runtime/node/jwk_to_key.ts @@ -1,13 +1,13 @@ import { createPrivateKey, createPublicKey, createSecretKey } from 'crypto' import type { KeyObject, PublicKeyInput, PrivateKeyInput } from 'crypto' -import type { JWKParseFunction } from '../interfaces' +import type { JWKParseFunction } from '../interfaces.d' import { decode as base64url } from './base64url.js' import { JOSENotSupported } from '../../util/errors.js' import { setCurve } from './get_named_curve.js' import { setModulusLength } from './check_modulus_length.js' import Asn1SequenceEncoder from './asn1_sequence_encoder.js' -import type { JWK } from '../../types' +import type { JWK } from '../../types.d' const [major, minor] = process.version .substr(1) diff --git a/src/runtime/node/key_to_jwk.ts b/src/runtime/node/key_to_jwk.ts index 294d385daa..ae1753ce0f 100644 --- a/src/runtime/node/key_to_jwk.ts +++ b/src/runtime/node/key_to_jwk.ts @@ -1,6 +1,6 @@ import { KeyObject, createPublicKey } from 'crypto' -import type { JWKConvertFunction } from '../interfaces' -import type { JWK } from '../../types' +import type { JWKConvertFunction } from '../interfaces.d' +import type { JWK } from '../../types.d' import { encode as base64url } from './base64url.js' import Asn1SequenceDecoder from './asn1_sequence_decoder.js' import { JOSENotSupported } from '../../util/errors.js' diff --git a/src/runtime/node/pbes2kw.ts b/src/runtime/node/pbes2kw.ts index 798df50e8a..5abf831f25 100644 --- a/src/runtime/node/pbes2kw.ts +++ b/src/runtime/node/pbes2kw.ts @@ -1,6 +1,6 @@ import { promisify } from 'util' import { pbkdf2 as pbkdf2cb } from 'crypto' -import type { Pbes2KWDecryptFunction, Pbes2KWEncryptFunction } from '../interfaces' +import type { Pbes2KWDecryptFunction, Pbes2KWEncryptFunction } from '../interfaces.d' import random from './random.js' import { p2s as concatSalt } from '../../lib/buffer_utils.js' import { encode as base64url } from './base64url.js' diff --git a/src/runtime/node/rsaes.ts b/src/runtime/node/rsaes.ts index 66fc30c697..219a0b68bd 100644 --- a/src/runtime/node/rsaes.ts +++ b/src/runtime/node/rsaes.ts @@ -1,5 +1,5 @@ import { KeyObject, publicEncrypt, constants, privateDecrypt } from 'crypto' -import type { RsaEsDecryptFunction, RsaEsEncryptFunction } from '../interfaces' +import type { RsaEsDecryptFunction, RsaEsEncryptFunction } from '../interfaces.d' import checkModulusLength from './check_modulus_length.js' import { isCryptoKey, getKeyObject } from './webcrypto.js' import isKeyObject from './is_key_object.js' diff --git a/src/runtime/node/sign.ts b/src/runtime/node/sign.ts index e8d2e1d38e..fbc2c6f32c 100644 --- a/src/runtime/node/sign.ts +++ b/src/runtime/node/sign.ts @@ -1,7 +1,7 @@ import * as crypto from 'crypto' import { promisify } from 'util' -import type { SignFunction } from '../interfaces' +import type { SignFunction } from '../interfaces.d' import nodeDigest from './dsa_digest.js' import hmacDigest from './hmac_digest.js' import nodeKey from './node_key.js' diff --git a/src/runtime/node/timing_safe_equal.ts b/src/runtime/node/timing_safe_equal.ts index fa7ed45a21..3d0981f22f 100644 --- a/src/runtime/node/timing_safe_equal.ts +++ b/src/runtime/node/timing_safe_equal.ts @@ -1,6 +1,6 @@ import { timingSafeEqual as impl } from 'crypto' -import type { TimingSafeEqual } from '../interfaces' +import type { TimingSafeEqual } from '../interfaces.d' const timingSafeEqual: TimingSafeEqual = impl diff --git a/src/runtime/node/verify.ts b/src/runtime/node/verify.ts index 5c5039f413..d58fae25cd 100644 --- a/src/runtime/node/verify.ts +++ b/src/runtime/node/verify.ts @@ -1,7 +1,7 @@ import * as crypto from 'crypto' import { promisify } from 'util' -import type { VerifyFunction } from '../interfaces' +import type { VerifyFunction } from '../interfaces.d' import nodeDigest from './dsa_digest.js' import nodeKey from './node_key.js' import sign from './sign.js' diff --git a/src/runtime/node/webcrypto.ts b/src/runtime/node/webcrypto.ts index 90309c3467..b48c29b779 100644 --- a/src/runtime/node/webcrypto.ts +++ b/src/runtime/node/webcrypto.ts @@ -19,7 +19,6 @@ if (util.types.isCryptoKey) { } } else { // @ts-expect-error - // eslint-disable-next-line @typescript-eslint/no-unused-vars impl = (obj): obj is CryptoKey => false } diff --git a/src/runtime/node/zlib.ts b/src/runtime/node/zlib.ts index cb4bf5b72b..30801a95bd 100644 --- a/src/runtime/node/zlib.ts +++ b/src/runtime/node/zlib.ts @@ -1,7 +1,7 @@ import { promisify } from 'util' import { inflateRaw as inflateRawCb, deflateRaw as deflateRawCb } from 'zlib' -import type { InflateFunction, DeflateFunction } from '../../types' +import type { InflateFunction, DeflateFunction } from '../../types.d' const inflateRaw = promisify(inflateRawCb) const deflateRaw = promisify(deflateRawCb) diff --git a/src/types.d.ts b/src/types.d.ts index b5807872a4..d21502cd2c 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -1,6 +1,77 @@ /// import type { KeyObject } from 'crypto' +export type { KeyObject } + +/** + * KeyLike are platform-specific references to keying material. + * + * [KeyObject](https://nodejs.org/api/crypto.html#crypto_class_keyobject) is a representation of a + * key/secret available in the Node.js runtime. You can obtain a KeyObject instance e.g. from: + * + * - [crypto.createPublicKey](https://nodejs.org/api/crypto.html#crypto_crypto_createpublickey_key) + * - [crypto.createPrivateKey](https://nodejs.org/api/crypto.html#crypto_crypto_createprivatekey_key) + * - [crypto.createSecretKey](https://nodejs.org/api/crypto.html#crypto_crypto_createsecretkey_key_encoding) + * - [crypto.generateKeyPair](https://nodejs.org/api/crypto.html#crypto_crypto_generatekeypair_type_options_callback) + * - [jose/jwk/parse](../functions/jwk_parse.parseJwk.md#readme) + * - [jose/util/generate_key_pair](../functions/util_generate_key_pair.generateKeyPair.md#readme) + * - [jose/util/generate_secret](../functions/util_generate_secret.generateSecret.md#readme) + * + * [CryptoKey](https://developer.mozilla.org/en-US/docs/Web/API/CryptoKey) is a representation of a + * key/secret available in the Browser runtime. You can obtain a CryptoKey instance e.g. from: + * + * - [SubtleCrypto.importKey](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey) + * - [SubtleCrypto.generateKey](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/generateKey) + * - [jose/jwk/parse](../functions/jwk_parse.parseJwk.md#readme) + * - [jose/util/generate_key_pair](../functions/util_generate_key_pair.generateKeyPair.md#readme) + * - [jose/util/generate_secret](../functions/util_generate_secret.generateSecret.md#readme) + * + * [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) + * is used exclusively for symmetric secret representations, a CryptoKey or KeyObject is + * preferred, but in Web Crypto API this isn't an option for some algorithms. + * In Node.js the [Buffer](https://nodejs.org/api/buffer.html#buffer_buffer) class is a subclass of Uint8Array + * class. `jose` APIs accept plain Buffers wherever Uint8Array are supported as well. + * + * @example (node) Public KeyObject from a PEM public key + * ```js + * import { createPublicKey } from 'crypto' + * + * const publicKey = createPublicKey(pem) + * ``` + * + * @example (node) Private KeyObject from a PEM private key + * ```js + * import { createPrivateKey } from 'crypto' + * + * const privateKey = createPrivateKey(pem) + * ``` + * + * @example (node) Secret KeyObject from hex encoded random bytes + * ```js + * import { createSecretKey } from 'crypto' + * + * const secretKey = createSecretKey(Buffer.from('7f908df6c8bd634f769c073a48986d77677b79bc6aa19b106f976f2db18d38c2', 'hex')) + * ``` + * + * @example (all runtimes) KeyLike from a JSON Web Key (JWK) + * ```js + * import { parseJwk } from 'jose/jwk/parse' + * + * const ecPublicKey = await parseJwk({ + * crv: 'P-256', + * kty: 'EC', + * x: 'ySK38C1jBdLwDsNWKzzBHqKYEE5Cgv-qjWvorUXk9fw', + * y: '_LeQBw07cf5t57Iavn4j-BqJsAD1dpoz8gokd3sBsOo' + * }, 'ES256') + * + * const rsaPublicKey = await parseJwk({ + * kty: 'RSA', + * e: 'AQAB', + * n: '12oBZRhCiZFJLcPg59LkZZ9mdhSMTKAQZYq32k_ti5SBB6jerkh-WzOMAO664r_qyLkqHUSp3u5SbXtseZEpN3XPWGKSxjsy-1JyEFTdLSYe6f9gfrmxkUF_7DTpq0gn6rntP05g2-wFW50YO7mosfdslfrTJYWHFhJALabAeYirYD7-9kqq9ebfFMF4sRRELbv9oi36As6Q9B3Qb5_C1rAzqfao_PCsf9EPsTZsVVVkA5qoIAr47lo1ipfiBPxUCCNSdvkmDTYgvvRm6ZoMjFbvOtgyts55fXKdMWv7I9HMD5HwE9uW839PWA514qhbcIsXEYSFMPMV6fnlsiZvQQ' + * }, 'PS256') + * ``` + */ +export type KeyLike = KeyObject | CryptoKey | Uint8Array /** * JSON Web Key ([JWK](https://tools.ietf.org/html/rfc7517)). @@ -81,78 +152,6 @@ export interface GetKeyFunction { (protectedHeader: T, token: T2): Promise } -/* eslint-disable jsdoc/require-description-complete-sentence */ -/** - * KeyLike are platform-specific references to keying material. - * - * [KeyObject](https://nodejs.org/api/crypto.html#crypto_class_keyobject) is a representation of a - * key/secret available in the Node.js runtime. You can obtain a KeyObject instance e.g. from: - * - * - [crypto.createPublicKey](https://nodejs.org/api/crypto.html#crypto_crypto_createpublickey_key) - * - [crypto.createPrivateKey](https://nodejs.org/api/crypto.html#crypto_crypto_createprivatekey_key) - * - [crypto.createSecretKey](https://nodejs.org/api/crypto.html#crypto_crypto_createsecretkey_key_encoding) - * - [crypto.generateKeyPair](https://nodejs.org/api/crypto.html#crypto_crypto_generatekeypair_type_options_callback) - * - [jose/jwk/parse](../functions/jwk_parse.parseJwk.md#readme) - * - [jose/util/generate_key_pair](../functions/util_generate_key_pair.generateKeyPair.md#readme) - * - [jose/util/generate_secret](../functions/util_generate_secret.generateSecret.md#readme) - * - * [CryptoKey](https://developer.mozilla.org/en-US/docs/Web/API/CryptoKey) is a representation of a - * key/secret available in the Browser runtime. You can obtain a CryptoKey instance e.g. from: - * - * - [SubtleCrypto.importKey](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey) - * - [SubtleCrypto.generateKey](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/generateKey) - * - [jose/jwk/parse](../functions/jwk_parse.parseJwk.md#readme) - * - [jose/util/generate_key_pair](../functions/util_generate_key_pair.generateKeyPair.md#readme) - * - [jose/util/generate_secret](../functions/util_generate_secret.generateSecret.md#readme) - * - * [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) - * is used exclusively for symmetric secret representations, a CryptoKey or KeyObject is - * preferred, but in Web Crypto API this isn't an option for some algorithms. - * In Node.js the [Buffer](https://nodejs.org/api/buffer.html#buffer_buffer) class is a subclass of Uint8Array - * class. `jose` APIs accept plain Buffers wherever Uint8Array are supported as well. - * - * @example (node) Public KeyObject from a PEM public key - * ```js - * import { createPublicKey } from 'crypto' - * - * const publicKey = createPublicKey(pem) - * ``` - * - * @example (node) Private KeyObject from a PEM private key - * ```js - * import { createPrivateKey } from 'crypto' - * - * const privateKey = createPrivateKey(pem) - * ``` - * - * @example (node) Secret KeyObject from hex encoded random bytes - * ```js - * import { createSecretKey } from 'crypto' - * - * const secretKey = createSecretKey(Buffer.from('7f908df6c8bd634f769c073a48986d77677b79bc6aa19b106f976f2db18d38c2', 'hex')) - * ``` - * - * @example (all runtimes) KeyLike from a JSON Web Key (JWK) - * ```js - * import { parseJwk } from 'jose/jwk/parse' - * - * const ecPublicKey = await parseJwk({ - * crv: 'P-256', - * kty: 'EC', - * x: 'ySK38C1jBdLwDsNWKzzBHqKYEE5Cgv-qjWvorUXk9fw', - * y: '_LeQBw07cf5t57Iavn4j-BqJsAD1dpoz8gokd3sBsOo' - * }, 'ES256') - * - * const rsaPublicKey = await parseJwk({ - * kty: 'RSA', - * e: 'AQAB', - * n: '12oBZRhCiZFJLcPg59LkZZ9mdhSMTKAQZYq32k_ti5SBB6jerkh-WzOMAO664r_qyLkqHUSp3u5SbXtseZEpN3XPWGKSxjsy-1JyEFTdLSYe6f9gfrmxkUF_7DTpq0gn6rntP05g2-wFW50YO7mosfdslfrTJYWHFhJALabAeYirYD7-9kqq9ebfFMF4sRRELbv9oi36As6Q9B3Qb5_C1rAzqfao_PCsf9EPsTZsVVVkA5qoIAr47lo1ipfiBPxUCCNSdvkmDTYgvvRm6ZoMjFbvOtgyts55fXKdMWv7I9HMD5HwE9uW839PWA514qhbcIsXEYSFMPMV6fnlsiZvQQ' - * }, 'PS256') - * ``` - */ -export type KeyLike = KeyObject | CryptoKey | Uint8Array -/* eslint-enable */ - /** * Flattened JWS definition for verify function inputs, allows payload as * Uint8Array for detached signature validation. diff --git a/src/util/base64url.ts b/src/util/base64url.ts index 318a53e155..1ba3c89005 100644 --- a/src/util/base64url.ts +++ b/src/util/base64url.ts @@ -1,5 +1,3 @@ -/* eslint-disable prefer-destructuring */ - import * as base64url from '../runtime/base64url.js' /** diff --git a/src/util/decode_protected_header.ts b/src/util/decode_protected_header.ts index 733e2c23ef..0edf79e9a2 100644 --- a/src/util/decode_protected_header.ts +++ b/src/util/decode_protected_header.ts @@ -1,7 +1,7 @@ import { decode as base64url } from './base64url.js' import { decoder } from '../lib/buffer_utils.js' import isObject from '../lib/is_object.js' -import type { JWSHeaderParameters, JWEHeaderParameters } from '../types' +import type { JWSHeaderParameters, JWEHeaderParameters } from '../types.d' export type ProtectedHeaderParameters = JWSHeaderParameters & JWEHeaderParameters @@ -18,6 +18,11 @@ export type ProtectedHeaderParameters = JWSHeaderParameters & JWEHeaderParameter * const { decodeProtectedHeader } = require('jose/util/decode_protected_header') * ``` * + * @example Deno import + * ```js + * import { decodeProtectedHeader } from 'https://deno.land/x/jose@VERSION/util/decode_protected_header.ts' + * ``` + * * @example Usage * ```js * const protectedHeader = decodeProtectedHeader(token) diff --git a/src/util/errors.ts b/src/util/errors.ts index 151f909db2..59ef9a38db 100644 --- a/src/util/errors.ts +++ b/src/util/errors.ts @@ -1,5 +1,3 @@ -/* eslint-disable max-classes-per-file */ - /** * A generic Error subclass that all other specific * JOSE Error subclasses inherit from. diff --git a/src/util/generate_key_pair.ts b/src/util/generate_key_pair.ts index dffdc05826..6193a68d18 100644 --- a/src/util/generate_key_pair.ts +++ b/src/util/generate_key_pair.ts @@ -1,5 +1,5 @@ import { generateKeyPair as generate } from '../runtime/generate.js' -import type { KeyLike } from '../types' +import type { KeyLike } from '../types.d' export interface GenerateKeyPairResult { /** @@ -53,6 +53,11 @@ export interface GenerateKeyPairOptions { * const { generateKeyPair } = require('jose/util/generate_key_pair') * ``` * + * @example Deno import + * ```js + * import { generateKeyPair } from 'https://deno.land/x/jose@VERSION/util/generate_key_pair.ts' + * ``` + * * @example Usage * ```js * const { publicKey, privateKey } = await generateKeyPair('PS256') diff --git a/src/util/generate_secret.ts b/src/util/generate_secret.ts index 6cbe30e075..b0904e3f83 100644 --- a/src/util/generate_secret.ts +++ b/src/util/generate_secret.ts @@ -1,5 +1,5 @@ import { generateSecret as generate } from '../runtime/generate.js' -import type { KeyLike } from '../types' +import type { KeyLike } from '../types.d' export interface GenerateSecretOptions { /** @@ -26,6 +26,11 @@ export interface GenerateSecretOptions { * const { generateSecret } = require('jose/util/generate_secret') * ``` * + * @example Deno import + * ```js + * import { generateSecret } from 'https://deno.land/x/jose@VERSION/util/generate_secret.ts' + * ``` + * * @example Usage * ```js * const secret = await generateSecret('HS256') diff --git a/test-browser/.eslintrc.json b/test-browser/.eslintrc.json deleted file mode 100644 index 38a6685580..0000000000 --- a/test-browser/.eslintrc.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "globals": { - "fetch": true, - "window": true, - "QUnit": true - }, - "extends": "airbnb-base", - "rules": { - "import/no-extraneous-dependencies": "off", - "import/no-unresolved": "off" - } -} diff --git a/test-browser/jwe_asymmetric.js b/test-browser/jwe_asymmetric.js index 6fef297d50..b40503a4aa 100644 --- a/test-browser/jwe_asymmetric.js +++ b/test-browser/jwe_asymmetric.js @@ -23,7 +23,6 @@ async function test(generate, alg, assert) { assert.ok(1); } -// eslint-disable-next-line no-restricted-syntax for (const crv of ['P-256', 'P-384', 'P-521']) { if (crv === 'P-521' && !p521) { QUnit.test(`ECDH-ES crv: ${crv}`, async (assert) => { diff --git a/test-deno/.prettierrc.json b/test-deno/.prettierrc.json new file mode 100644 index 0000000000..d2bd3c8912 --- /dev/null +++ b/test-deno/.prettierrc.json @@ -0,0 +1,6 @@ +{ + "trailingComma": "all", + "singleQuote": true, + "printWidth": 100, + "semi": true +} diff --git a/test-deno/generate_keys.test.ts b/test-deno/generate_keys.test.ts new file mode 100644 index 0000000000..45b9a9e73f --- /dev/null +++ b/test-deno/generate_keys.test.ts @@ -0,0 +1,76 @@ +import { assertStrictEquals } from 'https://deno.land/std@0.104.0/testing/asserts.ts'; + +import generateKeyPair from '../dist/deno/util/generate_key_pair.ts'; + +Deno.test('Generate PS256 keys', async () => { + await generateKeyPair('PS256'); +}); + +Deno.test('extractable', async () => { + let { privateKey, publicKey } = await generateKeyPair('PS256'); + assertStrictEquals(publicKey.extractable, true); + assertStrictEquals(privateKey.extractable, false); + + ({ privateKey } = await generateKeyPair('PS256', { extractable: true })); + assertStrictEquals(privateKey.extractable, true); +}); + +Deno.test('Generate PS384 keys', async () => { + await generateKeyPair('PS384'); +}); + +Deno.test('Generate PS512 keys', async () => { + await generateKeyPair('PS512'); +}); + +Deno.test('Generate RS256 keys', async () => { + await generateKeyPair('RS256'); +}); + +Deno.test('Generate RS384 keys', async () => { + await generateKeyPair('RS384'); +}); + +Deno.test('Generate RS512 keys', async () => { + await generateKeyPair('RS512'); +}); + +Deno.test('Generate ES256 keys', async () => { + await generateKeyPair('ES256'); +}); + +Deno.test('Generate ES384 keys', async () => { + await generateKeyPair('ES384'); +}); + +Deno.test('Generate ES512 keys', async () => { + await generateKeyPair('ES512'); +}); + +Deno.test('Generate RSA-OAEP keys', async () => { + await generateKeyPair('RSA-OAEP'); +}); + +Deno.test('Generate RSA-OAEP-256 keys', async () => { + await generateKeyPair('RSA-OAEP-256'); +}); + +Deno.test('Generate RSA-OAEP-384 keys', async () => { + await generateKeyPair('RSA-OAEP-384'); +}); + +Deno.test('Generate RSA-OAEP-512 keys', async () => { + await generateKeyPair('RSA-OAEP-512'); +}); + +Deno.test('Generate ECDH-ES crv: P-256 keys', async () => { + await generateKeyPair('ECDH-ES', { crv: 'P-256' }); +}); + +Deno.test('Generate ECDH-ES crv: P-384 keys', async () => { + await generateKeyPair('ECDH-ES', { crv: 'P-384' }); +}); + +Deno.test('Generate ECDH-ES crv: P-521 keys', async () => { + await generateKeyPair('ECDH-ES', { crv: 'P-521' }); +}); diff --git a/test-deno/generate_secrets.test.ts b/test-deno/generate_secrets.test.ts new file mode 100644 index 0000000000..cb8501cee1 --- /dev/null +++ b/test-deno/generate_secrets.test.ts @@ -0,0 +1,70 @@ +import { assertStrictEquals } from 'https://deno.land/std@0.104.0/testing/asserts.ts'; + +import generateSecret from '../dist/deno/util/generate_secret.ts'; + +Deno.test('Generate HS256 secret', async () => { + await generateSecret('HS256'); +}); + +Deno.test('extractable', async () => { + let secret = await generateSecret('HS256'); + assertStrictEquals(secret.extractable, false); + secret = await generateSecret('HS256', { extractable: true }); + assertStrictEquals(secret.extractable, true); +}); + +Deno.test('Generate HS384 secret', async () => { + await generateSecret('HS384'); +}); + +Deno.test('Generate HS512 secret', async () => { + await generateSecret('HS512'); +}); + +Deno.test('Generate A128CBC-HS256 secret', async () => { + await generateSecret('A128CBC-HS256'); +}); + +Deno.test('Generate A192CBC-HS384 secret', async () => { + await generateSecret('A192CBC-HS384'); +}); + +Deno.test('Generate A256CBC-HS512 secret', async () => { + await generateSecret('A256CBC-HS512'); +}); + +Deno.test('Generate A128KW secret', async () => { + await generateSecret('A128KW'); +}); + +Deno.test('Generate A192KW secret', async () => { + await generateSecret('A192KW'); +}); + +Deno.test('Generate A256KW secret', async () => { + await generateSecret('A256KW'); +}); + +Deno.test('Generate A128GCMKW secret', async () => { + await generateSecret('A128GCMKW'); +}); + +Deno.test('Generate A192GCMKW secret', async () => { + await generateSecret('A192GCMKW'); +}); + +Deno.test('Generate A256GCMKW secret', async () => { + await generateSecret('A256GCMKW'); +}); + +Deno.test('Generate A128GCM secret', async () => { + await generateSecret('A128GCM'); +}); + +Deno.test('Generate A192GCM secret', async () => { + await generateSecret('A192GCM'); +}); + +Deno.test('Generate A256GCM secret', async () => { + await generateSecret('A256GCM'); +}); diff --git a/test-deno/jwe_asymmetric.test.ts b/test-deno/jwe_asymmetric.test.ts new file mode 100644 index 0000000000..a99293848b --- /dev/null +++ b/test-deno/jwe_asymmetric.test.ts @@ -0,0 +1,43 @@ +import { assert } from 'https://deno.land/std@0.104.0/testing/asserts.ts'; + +import generateKeyPair from '../dist/deno/util/generate_key_pair.ts'; +import random from '../dist/deno/util/random.ts'; +import FlattenedEncrypt from '../dist/deno/jwe/flattened/encrypt.ts'; +import decryptFlattened from '../dist/deno/jwe/flattened/decrypt.ts'; +import decodeProtectedHeader from '../dist/deno/util/decode_protected_header.ts'; + +async function test(generate, alg) { + const { publicKey, privateKey } = await generate(); + + const jwe = await new FlattenedEncrypt(random(new Uint8Array(32))) + .setProtectedHeader({ alg, enc: 'A256GCM' }) + .setAdditionalAuthenticatedData(random(new Uint8Array(32))) + .encrypt(publicKey); + + assert(decodeProtectedHeader(jwe)); + await decryptFlattened(jwe, privateKey); +} + +for (const crv of ['P-256', 'P-384', 'P-521']) { + Deno.test( + `Encrypt/Decrypt ECDH-ES crv: ${crv}`, + test.bind(undefined, generateKeyPair.bind(undefined, 'ECDH-ES', { crv }), 'ECDH-ES'), + ); +} + +Deno.test( + 'Encrypt/Decrypt RSA-OAEP-256', + test.bind(undefined, generateKeyPair.bind(undefined, 'RSA-OAEP-256'), 'RSA-OAEP-256'), +); +Deno.test( + 'Encrypt/Decrypt RSA-OAEP-384', + test.bind(undefined, generateKeyPair.bind(undefined, 'RSA-OAEP-384'), 'RSA-OAEP-384'), +); +Deno.test( + 'Encrypt/Decrypt RSA-OAEP-512', + test.bind(undefined, generateKeyPair.bind(undefined, 'RSA-OAEP-512'), 'RSA-OAEP-512'), +); +Deno.test( + 'Encrypt/Decrypt RSA-OAEP', + test.bind(undefined, generateKeyPair.bind(undefined, 'RSA-OAEP'), 'RSA-OAEP'), +); diff --git a/test-deno/jwe_symmetric.test.ts b/test-deno/jwe_symmetric.test.ts new file mode 100644 index 0000000000..513ec084cb --- /dev/null +++ b/test-deno/jwe_symmetric.test.ts @@ -0,0 +1,139 @@ +import { assert } from 'https://deno.land/std@0.104.0/testing/asserts.ts'; + +import generateSecret from '../dist/deno/util/generate_secret.ts'; +import random from '../dist/deno/util/random.ts'; +import FlattenedEncrypt from '../dist/deno/jwe/flattened/encrypt.ts'; +import decryptFlattened from '../dist/deno/jwe/flattened/decrypt.ts'; +import decodeProtectedHeader from '../dist/deno/util/decode_protected_header.ts'; + +async function test(generate, { alg, enc }) { + const secretKey = await generate(); + + const jwe = await new FlattenedEncrypt(random(new Uint8Array(32))) + .setProtectedHeader({ alg, enc }) + .setAdditionalAuthenticatedData(random(new Uint8Array(32))) + .encrypt(secretKey); + + assert(decodeProtectedHeader(jwe)); + await decryptFlattened(jwe, secretKey); +} + +Deno.test( + 'Encrypt/Decrypt A128CBC-HS256', + test.bind(undefined, generateSecret.bind(undefined, 'A128CBC-HS256'), { + alg: 'dir', + enc: 'A128CBC-HS256', + }), +); + +Deno.test( + 'Encrypt/Decrypt A128GCM', + test.bind(undefined, generateSecret.bind(undefined, 'A128GCM'), { + alg: 'dir', + enc: 'A128GCM', + }), +); + +Deno.test( + 'Encrypt/Decrypt A192CBC-HS384', + test.bind(undefined, generateSecret.bind(undefined, 'A192CBC-HS384'), { + alg: 'dir', + enc: 'A192CBC-HS384', + }), +); + +Deno.test( + 'Encrypt/Decrypt A192GCM', + test.bind(undefined, generateSecret.bind(undefined, 'A192GCM'), { + alg: 'dir', + enc: 'A192GCM', + }), +); + +Deno.test( + 'Encrypt/Decrypt A256CBC-HS512', + test.bind(undefined, generateSecret.bind(undefined, 'A256CBC-HS512'), { + alg: 'dir', + enc: 'A256CBC-HS512', + }), +); + +Deno.test( + 'Encrypt/Decrypt A256GCM', + test.bind(undefined, generateSecret.bind(undefined, 'A256GCM'), { + alg: 'dir', + enc: 'A256GCM', + }), +); + +Deno.test( + 'Encrypt/Decrypt A128GCMKW', + test.bind(undefined, generateSecret.bind(undefined, 'A128GCMKW'), { + alg: 'A128GCMKW', + enc: 'A256GCM', + }), +); + +Deno.test( + 'Encrypt/Decrypt A128KW', + test.bind(undefined, generateSecret.bind(undefined, 'A128KW'), { + alg: 'A128KW', + enc: 'A256GCM', + }), +); + +Deno.test( + 'Encrypt/Decrypt A192GCMKW', + test.bind(undefined, generateSecret.bind(undefined, 'A192GCMKW'), { + alg: 'A192GCMKW', + enc: 'A256GCM', + }), +); + +Deno.test( + 'Encrypt/Decrypt A192KW', + test.bind(undefined, generateSecret.bind(undefined, 'A192KW'), { + alg: 'A192KW', + enc: 'A256GCM', + }), +); + +Deno.test( + 'Encrypt/Decrypt A256GCMKW', + test.bind(undefined, generateSecret.bind(undefined, 'A256GCMKW'), { + alg: 'A256GCMKW', + enc: 'A256GCM', + }), +); + +Deno.test( + 'Encrypt/Decrypt A256KW', + test.bind(undefined, generateSecret.bind(undefined, 'A256KW'), { + alg: 'A256KW', + enc: 'A256GCM', + }), +); + +Deno.test( + 'Encrypt/Decrypt PBES2-HS256+A128KW', + test.bind(undefined, () => random(new Uint8Array(10)), { + alg: 'PBES2-HS256+A128KW', + enc: 'A256GCM', + }), +); + +Deno.test( + 'Encrypt/Decrypt PBES2-HS384+A192KW', + test.bind(undefined, () => random(new Uint8Array(10)), { + alg: 'PBES2-HS384+A192KW', + enc: 'A256GCM', + }), +); + +Deno.test( + 'Encrypt/Decrypt PBES2-HS512+A256KW', + test.bind(undefined, () => random(new Uint8Array(10)), { + alg: 'PBES2-HS512+A256KW', + enc: 'A256GCM', + }), +); diff --git a/test-deno/jwks.test.ts b/test-deno/jwks.test.ts new file mode 100644 index 0000000000..f314dab1e1 --- /dev/null +++ b/test-deno/jwks.test.ts @@ -0,0 +1,23 @@ +import { assertThrowsAsync } from 'https://deno.land/std@0.104.0/testing/asserts.ts'; + +import createRemoteJWKSet from '../dist/deno/jwks/remote.ts'; +import { JWKSNoMatchingKey, JWKSMultipleMatchingKeys } from '../dist/deno/util/errors.ts'; + +const jwksUri = 'https://www.googleapis.com/oauth2/v3/certs'; + +Deno.test('fetches the JWKSet', async () => { + const response = await fetch(jwksUri).then((r) => r.json()); + const { alg, kid } = response.keys[0]; + const jwks = createRemoteJWKSet(new URL(jwksUri)); + await assertThrowsAsync( + () => jwks({ alg: 'RS256' }), + JWKSMultipleMatchingKeys, + 'multiple matching keys found in the JSON Web Key Set', + ); + await assertThrowsAsync( + () => jwks({ kid: 'foo', alg: 'RS256' }), + JWKSNoMatchingKey, + 'no applicable key found in the JSON Web Key Set', + ); + await jwks({ alg, kid }); +}); diff --git a/test-deno/jws.test.ts b/test-deno/jws.test.ts new file mode 100644 index 0000000000..cb4957609e --- /dev/null +++ b/test-deno/jws.test.ts @@ -0,0 +1,86 @@ +import { assert } from 'https://deno.land/std@0.104.0/testing/asserts.ts'; + +import generateKeyPair from '../dist/deno/util/generate_key_pair.ts'; +import generateSecret from '../dist/deno/util/generate_secret.ts'; +import random from '../dist/deno/util/random.ts'; +import FlattenedSign from '../dist/deno/jws/flattened/sign.ts'; +import verifyFlattened from '../dist/deno/jws/flattened/verify.ts'; +import decodeProtectedHeader from '../dist/deno/util/decode_protected_header.ts'; + +async function test(generate: any, alg: string) { + const generated = await generate(); + let privateKey: CryptoKey; + let publicKey: CryptoKey; + if (generated.type === 'secret') { + publicKey = privateKey = generated; + } else { + ({ publicKey, privateKey } = generated); + } + + const jws = await new FlattenedSign(random(new Uint8Array(32))) + .setProtectedHeader({ alg }) + .sign(privateKey); + + assert(decodeProtectedHeader(jws)); + await verifyFlattened({ ...jws }, publicKey); +} + +Deno.test( + 'Sign/Verify HS256', + test.bind(undefined, () => generateSecret('HS256'), 'HS256'), +); + +Deno.test( + 'Sign/Verify HS384', + test.bind(undefined, () => generateSecret('HS384'), 'HS384'), +); + +Deno.test( + 'Sign/Verify HS512', + test.bind(undefined, () => generateSecret('HS512'), 'HS512'), +); + +Deno.test( + 'Sign/Verify ES256', + test.bind(undefined, () => generateKeyPair('ES256'), 'ES256'), +); + +Deno.test( + 'Sign/Verify ES384', + test.bind(undefined, () => generateKeyPair('ES384'), 'ES384'), +); + +Deno.test( + 'Sign/Verify ES512', + test.bind(undefined, () => generateKeyPair('ES512'), 'ES512'), +); + +Deno.test( + 'Sign/Verify PS256', + test.bind(undefined, () => generateKeyPair('PS256'), 'PS256'), +); + +Deno.test( + 'Sign/Verify PS384', + test.bind(undefined, () => generateKeyPair('PS384'), 'PS384'), +); + +Deno.test( + 'Sign/Verify PS512', + test.bind(undefined, () => generateKeyPair('PS512'), 'PS512'), +); + +Deno.test( + 'Sign/Verify RS256', + test.bind(undefined, () => generateKeyPair('RS256'), 'RS256'), +); + +Deno.test( + 'Sign/Verify RS384', + test.bind(undefined, () => generateKeyPair('RS384'), 'RS384'), +); + +Deno.test( + 'Sign/Verify RS512', + test.bind(undefined, () => generateKeyPair('RS512'), 'RS512'), +); diff --git a/test-deno/keylike.test.ts b/test-deno/keylike.test.ts new file mode 100644 index 0000000000..e0799754f6 --- /dev/null +++ b/test-deno/keylike.test.ts @@ -0,0 +1,58 @@ +import { assertEquals } from 'https://deno.land/std@0.104.0/testing/asserts.ts'; + +import jwkToKey from '../dist/deno/jwk/parse.ts'; +import keyToJwk from '../dist/deno/jwk/from_key_like.ts'; +import calculateThumbprint from '../dist/deno/jwk/thumbprint.ts'; + +async function test(jwk: JsonWebKey, alg: string) { + await calculateThumbprint(jwk) + const keyLike = await jwkToKey(jwk, alg); + assertEquals(await keyToJwk(keyLike), jwk); +} + +for (const [alg, jwk] of [ + [ + 'RS256', + '{"kty":"RSA","n":"rcbWc-i_C8NtS4CpPcMF3QC025re_zzrhv-3ElzxAsMCCepwEqxCzQtsG7mAtROdGR1N_oNPNqr3jmEZdv5C5NtpPeX_gk4-r30_JLXcGNgVbZpmWVSmUI-nrU0cC3kjMS4RUPx7uDQxAUiVUq0k13qjEbEgcZAA3nEH2zuQWg3iWSmwYL0h1VxdINQ-WZZzBJsI_ONyBS5z3-vbyhtnMbgALRZSvNcYpODrH9AEIWNJhcaBVr1vKBdNT76KOl87ilLiKE1dOr72sLJDDsVqXDfxCjU_wdt2bF-YFcKwlYa5Aj2JF-UH7KLniC3P-2sS1zduLoAPAkyLcHgVdOifhQ","e":"AQAB","d":"gJwTJS-RDOyym9l558rJMRoPwCOrfG0ixwPEAuQkPu4COUJ3dWpl-gjFFvPATMNaVjb4_S9DVetMUeSNCyL8cRHtnrD03AR6ojhongu1-_EYUsidjOl4OVFIQJs78UXTBNfaWv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eqnABbBvUExYTd0_nhXU4IQMWtUaZ8C7UVia4PkhuS0M0Vd6lV_IGjIfJwJJlEVJy5YrrF5_SbeekS6DtjPrMNwzIc8nX6u17GjISy7eggryvf3V3YV9uFpfj9TmC8K3NgqV0cCEgajYLFZh3xSeQS6jp62XKW8tk","dq":"wfWewtIOEG157IqEeE_6f9TZemabeauUSoWcqhuSx98CmCz_uOa5WAlGLh6HLIMmdSJcfflScIhzI_GVL4O1xk6KxL-6ZbS1i1fmPt3-hVY7qf_gEqvN_1_SkAqGvkgQdB4QF_VXvu17sK3xYlPP9v52hBUNc7YrN1pO4fTUVsc","qi":"u8ZrPCzwWF5yhpNsPtba5MmnlG6GCvXdbD9TE0qm-ol4UnRqlzfQofNDToYBQ6g9Yl6yQsn5QEj3UG3oeIBjgnUJh1vH2OcyVucKe3iSvj6YQTOMDwma0YnSUoOmaDCOaUlpWTuyTPEU-eQVtYmgu-LI4k-gdbf9N--4HLnk9bs"}', + ], + [ + 'ES256', + '{"crv":"P-256","kty":"EC","x":"E8KpG0wpGUfRBYx8tUhd6tYaFaTZaIyHvAudXbSUFxQ","y":"gcVDlKTo-UhZ-wHDNUdoQP0M9zevurU6A5WMR07B-wQ","d":"m2lKgT3jxM3ouusu8sgjk2Ajqyf1L8KBLuRxQ3opSlY"}', + ], + [ + 'ES384', + '{"crv":"P-384","kty":"EC","x":"HnBAtgpS-GJzTCdLBELPm1VIRoQwlk7luJIGEYWKhWtMHmOq14Hh7674Oxcc52mE","y":"jXGek8Zapkjav7mO-KB-7vEWrqNxHSoXgNn1r6C0BiqS89SVciz6O8uriPdxoWem","d":"Fr-aKdB1GdA98B80LTNftu04p9RILDBSNRQxQ1chl4DS9CSZcw39aEZoSUAbJa6r"}', + ], + [ + 'ES512', + '{"crv":"P-521","kty":"EC","x":"AIwG869tNnEGIDg2hSyvXKIOk9rWPO_riIixGliBGBV0kB57QoTrjK-g5JCtazDTcBT23igX9gvAVkLvr2oFTQ9p","y":"AeGZ0Z3JHM1rQWvmmpdfVu0zSNpmu0xPjGUE2hGhloRqF-JJV3aVMS72ZhGlbWi-O7OCcypIfndhpYgrc3qx0Y1w","d":"AVIiopJk-cUIfQCJey-NvNbxiTB7haAB1AVvjp4r6wQ0ySw-RsKM03VbJNdWxcSsyHnk-mj-IP6wdWdeqUdto04T"}', + ], + ['HS256', '{"kty":"oct","k":"iPYq7qKZWRaVmo1FiJ17M84uADey7-veCAEEsxpPTus"}'], + ['HS384', '{"kty":"oct","k":"ATgNcVOYFsjbN4GeyXOyryfqqmGp_48-uvVd5J3GsX7ExUMp3WNTDbbZK_5kTjND"}'], + [ + 'HS512', + '{"kty":"oct","k":"2O5x_zEOhSIDiGcOAOYhB1dyDU_ZW27rl-_xDpKE-8tBlL91z6p_8aYo3by6AOsa6ycx6-JC9LBAio0amINXTQ"}', + ], +]) { + Deno.test(`Key Import/Export ${alg}`, test.bind(undefined, JSON.parse(jwk), alg)); +} diff --git a/test/.eslintrc.json b/test/.eslintrc.json deleted file mode 100644 index 181b7f293a..0000000000 --- a/test/.eslintrc.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "airbnb-base", - "rules": { - "import/no-extraneous-dependencies": "off", - "import/no-unresolved": "off" - } -} diff --git a/test/jwe/compact.decrypt.test.mjs b/test/jwe/compact.decrypt.test.mjs index d5e9d546cc..df35e905f7 100644 --- a/test/jwe/compact.decrypt.test.mjs +++ b/test/jwe/compact.decrypt.test.mjs @@ -1,4 +1,3 @@ -/* eslint-disable no-param-reassign */ import test from 'ava'; const root = !('WEBCRYPTO' in process.env) ? '#dist' : '#dist/webcrypto'; diff --git a/test/jwe/compact.encrypt.test.mjs b/test/jwe/compact.encrypt.test.mjs index 6896540dee..6be2d021b1 100644 --- a/test/jwe/compact.encrypt.test.mjs +++ b/test/jwe/compact.encrypt.test.mjs @@ -1,4 +1,3 @@ -/* eslint-disable no-param-reassign */ import test from 'ava'; const root = !('WEBCRYPTO' in process.env) ? '#dist' : '#dist/webcrypto'; diff --git a/test/jwe/cookbook.test.mjs b/test/jwe/cookbook.test.mjs index e1bd9f97b9..308be3f1ee 100644 --- a/test/jwe/cookbook.test.mjs +++ b/test/jwe/cookbook.test.mjs @@ -56,13 +56,11 @@ Promise.all([ if (reproducible) { // sign and compare results are the same - // eslint-disable-next-line no-restricted-syntax for (const [serialization, expectedResult] of [ [flattened, vector.output.json_flat], [compact, vector.output.compact], ]) { if (!expectedResult) { - // eslint-disable-next-line no-continue continue; } const encrypt = new serialization.Encrypt(encode(vector.input.plaintext)); diff --git a/test/jwe/flattened.decrypt.test.mjs b/test/jwe/flattened.decrypt.test.mjs index e8cbcef2cc..7f401fb73a 100644 --- a/test/jwe/flattened.decrypt.test.mjs +++ b/test/jwe/flattened.decrypt.test.mjs @@ -1,4 +1,3 @@ -/* eslint-disable no-param-reassign */ import test from 'ava'; const root = !('WEBCRYPTO' in process.env) ? '#dist' : '#dist/webcrypto'; diff --git a/test/jwe/flattened.encrypt.test.mjs b/test/jwe/flattened.encrypt.test.mjs index 6174fd3eb8..77fd57b79a 100644 --- a/test/jwe/flattened.encrypt.test.mjs +++ b/test/jwe/flattened.encrypt.test.mjs @@ -1,4 +1,3 @@ -/* eslint-disable no-param-reassign */ import test from 'ava'; const root = !('WEBCRYPTO' in process.env) ? '#dist' : '#dist/webcrypto'; diff --git a/test/jwe/general.decrypt.test.mjs b/test/jwe/general.decrypt.test.mjs index 547a001602..54f75372ff 100644 --- a/test/jwe/general.decrypt.test.mjs +++ b/test/jwe/general.decrypt.test.mjs @@ -1,4 +1,3 @@ -/* eslint-disable no-param-reassign */ import test from 'ava'; const root = !('WEBCRYPTO' in process.env) ? '#dist' : '#dist/webcrypto'; diff --git a/test/jwe/smoke.test.mjs b/test/jwe/smoke.test.mjs index e68ab64996..eb72bf166e 100644 --- a/test/jwe/smoke.test.mjs +++ b/test/jwe/smoke.test.mjs @@ -1,8 +1,3 @@ -/* eslint-disable no-await-in-loop */ -/* eslint-disable no-restricted-syntax */ -/* eslint-disable no-bitwise */ -/* eslint-disable no-param-reassign */ - import test from 'ava'; let root; diff --git a/test/jwk/embedded.test.mjs b/test/jwk/embedded.test.mjs index e645929068..66c25c08db 100644 --- a/test/jwk/embedded.test.mjs +++ b/test/jwk/embedded.test.mjs @@ -1,4 +1,3 @@ -/* eslint-disable no-param-reassign */ import test from 'ava'; let root; diff --git a/test/jwks/remote.test.mjs b/test/jwks/remote.test.mjs index 7052c11bc1..d5b6981af7 100644 --- a/test/jwks/remote.test.mjs +++ b/test/jwks/remote.test.mjs @@ -1,4 +1,3 @@ -/* eslint-disable no-param-reassign */ import test from 'ava'; import nock from 'nock'; import timekeeper from 'timekeeper'; diff --git a/test/jws/compact.sign.test.mjs b/test/jws/compact.sign.test.mjs index 625d2f1b01..7d29bbe150 100644 --- a/test/jws/compact.sign.test.mjs +++ b/test/jws/compact.sign.test.mjs @@ -1,4 +1,3 @@ -/* eslint-disable no-param-reassign */ import test from 'ava'; const root = !('WEBCRYPTO' in process.env) ? '#dist' : '#dist/webcrypto'; diff --git a/test/jws/compact.verify.test.mjs b/test/jws/compact.verify.test.mjs index 1141fd8d12..1cfe87023d 100644 --- a/test/jws/compact.verify.test.mjs +++ b/test/jws/compact.verify.test.mjs @@ -1,4 +1,3 @@ -/* eslint-disable no-param-reassign */ import test from 'ava'; const root = !('WEBCRYPTO' in process.env) ? '#dist' : '#dist/webcrypto'; diff --git a/test/jws/cookbook.test.mjs b/test/jws/cookbook.test.mjs index c7f43375e4..2ebec177e9 100644 --- a/test/jws/cookbook.test.mjs +++ b/test/jws/cookbook.test.mjs @@ -54,7 +54,6 @@ Promise.all([ } for (const [serialization, expectedResult] of runs) { if (!expectedResult) { - // eslint-disable-next-line no-continue continue; } const sign = new serialization.Sign(encode(vector.input.payload)); diff --git a/test/jws/flattened.sign.test.mjs b/test/jws/flattened.sign.test.mjs index 450af267c6..1a0af530a1 100644 --- a/test/jws/flattened.sign.test.mjs +++ b/test/jws/flattened.sign.test.mjs @@ -1,4 +1,3 @@ -/* eslint-disable no-param-reassign */ import test from 'ava'; const root = !('WEBCRYPTO' in process.env) ? '#dist' : '#dist/webcrypto'; diff --git a/test/jws/flattened.verify.test.mjs b/test/jws/flattened.verify.test.mjs index d1b3b57c12..7622eaf6a2 100644 --- a/test/jws/flattened.verify.test.mjs +++ b/test/jws/flattened.verify.test.mjs @@ -1,4 +1,3 @@ -/* eslint-disable no-param-reassign */ import test from 'ava'; const root = !('WEBCRYPTO' in process.env) ? '#dist' : '#dist/webcrypto'; diff --git a/test/jws/general.test.mjs b/test/jws/general.test.mjs index af1ff2d2f1..88eead9956 100644 --- a/test/jws/general.test.mjs +++ b/test/jws/general.test.mjs @@ -1,4 +1,3 @@ -/* eslint-disable no-param-reassign */ import test from 'ava'; const root = !('WEBCRYPTO' in process.env) ? '#dist' : '#dist/webcrypto'; diff --git a/test/jws/restrictions.test.mjs b/test/jws/restrictions.test.mjs index 0c02c96518..9c5a3796ca 100644 --- a/test/jws/restrictions.test.mjs +++ b/test/jws/restrictions.test.mjs @@ -1,4 +1,3 @@ -/* eslint-disable no-param-reassign */ import test from 'ava'; import * as crypto from 'crypto'; diff --git a/test/jws/smoke.test.mjs b/test/jws/smoke.test.mjs index cc6aef55d8..88a747c851 100644 --- a/test/jws/smoke.test.mjs +++ b/test/jws/smoke.test.mjs @@ -1,8 +1,3 @@ -/* eslint-disable no-await-in-loop */ -/* eslint-disable no-restricted-syntax */ -/* eslint-disable no-bitwise */ -/* eslint-disable no-param-reassign */ - import test from 'ava'; let root; diff --git a/test/jwt/encrypt.test.mjs b/test/jwt/encrypt.test.mjs index 2b9a3b0b27..26eb5cdd47 100644 --- a/test/jwt/encrypt.test.mjs +++ b/test/jwt/encrypt.test.mjs @@ -1,4 +1,3 @@ -/* eslint-disable no-param-reassign */ import test from 'ava'; import timekeeper from 'timekeeper'; diff --git a/test/jwt/sign.test.mjs b/test/jwt/sign.test.mjs index 90c5b3bacb..e28e5b4b29 100644 --- a/test/jwt/sign.test.mjs +++ b/test/jwt/sign.test.mjs @@ -1,4 +1,3 @@ -/* eslint-disable no-param-reassign */ import test from 'ava'; import timekeeper from 'timekeeper'; diff --git a/test/jwt/unsecured.test.mjs b/test/jwt/unsecured.test.mjs index 56a1654f80..dc77b672b3 100644 --- a/test/jwt/unsecured.test.mjs +++ b/test/jwt/unsecured.test.mjs @@ -1,4 +1,3 @@ -/* eslint-disable no-param-reassign */ import test from 'ava'; import timekeeper from 'timekeeper'; diff --git a/tools/docs.postbump.js b/tools/docs.postbump.js deleted file mode 100755 index 5634202e80..0000000000 --- a/tools/docs.postbump.js +++ /dev/null @@ -1,13 +0,0 @@ -require("./explode-exports"); -const { execSync } = require("child_process"); -const { readFileSync, writeFileSync } = require("fs"); -const { version } = require("../package.json"); - -const readme = readFileSync("docs/README.md"); -const tagName = `v${version}`; - -execSync("git rm docs/**/*.md"); -execSync('find docs -type d | grep "docs/" | xargs rm -rf'); -execSync(`npm run docs:generate -- --gitRevision ${tagName}`); -writeFileSync("docs/README.md", readme); -execSync("git add docs/**/*.md"); diff --git a/tools/postbump.js b/tools/postbump.js new file mode 100755 index 0000000000..573e00cdc1 --- /dev/null +++ b/tools/postbump.js @@ -0,0 +1,31 @@ +const { x } = require("tar"); + +require("./explode-exports"); +const { execSync } = require("child_process"); +const { readFileSync, writeFileSync } = require("fs"); +const { version } = require("../package.json"); + +const readme = readFileSync("docs/README.md"); +const tagName = `v${version}`; +const opts = { stdio: "inherit" }; + +execSync("git rm -f docs/**/*.md", opts); +execSync('find docs -type d | grep "docs/" | xargs rm -rf', opts); +execSync( + `npm run docs:generate -- --plugin ./tools/typedoc-replace-version --gitRevision ${tagName}`, + opts +); +writeFileSync("docs/README.md", readme); +execSync("git add docs/**/*.md", opts); +execSync("npm pack", opts); + +x({ + f: `jose-${version}.tgz`, + strip: true, + filter(loc) { + return loc.startsWith("package/dist/"); + }, + sync: true, +}); +execSync("npm run build:deno", opts); +execSync("git add dist/**/* -f", opts); diff --git a/tools/typedoc-replace-version.js b/tools/typedoc-replace-version.js new file mode 100644 index 0000000000..5e1e55b73c --- /dev/null +++ b/tools/typedoc-replace-version.js @@ -0,0 +1,19 @@ +const { + Converter: { EVENT_RESOLVE_BEGIN }, +} = require("typedoc"); + +module.exports.load = function load(app) { + const gitRevision = app.options.getValue("gitRevision"); + if (gitRevision && gitRevision !== "main") { + app.converter.on(EVENT_RESOLVE_BEGIN, ({ project: { reflections } }) => { + for (const key in reflections) { + const reflection = reflections[key]; + if (reflection.comment && reflection.comment.tags) { + for (const tag of reflection.comment.tags) { + tag.text = tag.text.replace(/VERSION/g, gitRevision); + } + } + } + }); + } +};