Skip to content

Commit

Permalink
feat: experimental Deno build & publish
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Aug 20, 2021
1 parent 59aa96d commit 5c7d265
Show file tree
Hide file tree
Showing 112 changed files with 877 additions and 336 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 23 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion .versionrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ Legend:
| -- | -- | -- |
| Node.js | LTS ^12.19.0 || ^14.15.0 | |
| Electron | ^12.0.0 | see <sup>[1]</sup> |
| 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] | |
Expand Down
47 changes: 23 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"decode",
"decrypt",
"detached",
"deno",
"ec",
"ecdsa",
"eddsa",
Expand Down Expand Up @@ -301,6 +302,16 @@
"require": "./dist/node/cjs/util/random.js"
}
},
"typesVersions": {
"*": {
"webcrypto/*": [
"./dist/types/*"
],
"*": [
"./dist/types/*"
]
}
},
"files": [
"dist/**/package.json",
"dist/**/*.js",
Expand All @@ -316,25 +327,27 @@
"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",
"coverage-webcrypto": "npm run-script runtime-node-webcrypto && c8 npm run-script test-webcrypto",
"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",
Expand All @@ -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",
Expand All @@ -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/*"
]
}
}
}
41 changes: 0 additions & 41 deletions src/.eslintrc.json

This file was deleted.

8 changes: 6 additions & 2 deletions src/jwe/compact/decrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {
GetKeyFunction,
FlattenedJWE,
CompactDecryptResult,
} from '../../types'
} from '../../types.d'

/**
* Interface for Compact JWE Decryption dynamic key resolution.
Expand All @@ -33,6 +33,11 @@ export interface CompactDecryptGetKey extends GetKeyFunction<JWEHeaderParameters
* const { compactDecrypt } = require('jose/jwe/compact/decrypt')
* ```
*
* @example Deno import
* ```js
* import { compactDecrypt } from 'https://deno.land/x/jose@VERSION/jwe/compact/decrypt.ts'
* ```
*
* @example Usage
* ```js
* const decoder = new TextDecoder()
Expand All @@ -50,7 +55,6 @@ async function compactDecrypt(
options?: DecryptOptions,
): Promise<CompactDecryptResult> {
if (jwe instanceof Uint8Array) {
// eslint-disable-next-line no-param-reassign
jwe = decoder.decode(jwe)
}

Expand Down
7 changes: 6 additions & 1 deletion src/jwe/compact/encrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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()
Expand Down
8 changes: 6 additions & 2 deletions src/jwe/flattened/decrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -180,7 +185,6 @@ async function flattenedDecrypt(
}

if (typeof key === 'function') {
// eslint-disable-next-line no-param-reassign
key = await key(parsedProt, jwe)
}

Expand Down
9 changes: 7 additions & 2 deletions src/jwe/flattened/encrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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()
Expand Down
9 changes: 6 additions & 3 deletions src/jwe/general/decrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {
FlattenedJWE,
GeneralJWE,
GeneralDecryptResult,
} from '../../types'
} from '../../types.d'
import isObject from '../../lib/is_object.js'

/**
Expand All @@ -34,6 +34,11 @@ export interface GeneralDecryptGetKey extends GetKeyFunction<JWEHeaderParameters
* const { generalDecrypt } = require('jose/jwe/general/decrypt')
* ```
*
* @example Deno import
* ```js
* import { generalDecrypt } from 'https://deno.land/x/jose@VERSION/jwe/general/decrypt.ts'
* ```
*
* @example Usage
* ```js
* const decoder = new TextDecoder()
Expand Down Expand Up @@ -74,10 +79,8 @@ async function generalDecrypt(
throw new JWEInvalid('JWE Recipients missing or incorrect type')
}

// eslint-disable-next-line no-restricted-syntax
for (const recipient of jwe.recipients) {
try {
// eslint-disable-next-line no-await-in-loop
return await decrypt(
{
aad: jwe.aad,
Expand Down
10 changes: 6 additions & 4 deletions src/jwk/embedded.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/* eslint-disable jsdoc/require-param */
import type { KeyObject } from 'crypto'
import type { FlattenedJWSInput, JWSHeaderParameters } from '../types'
import type { KeyObject, FlattenedJWSInput, JWSHeaderParameters } from '../types.d'
import parseJwk from './parse.js'
import isObject from '../lib/is_object.js'
import { JWSInvalid } from '../util/errors.js'
Expand All @@ -22,6 +20,11 @@ import { JWSInvalid } from '../util/errors.js'
* const { EmbeddedJWK } = require('jose/jwk/embedded')
* ```
*
* @example Deno import
* ```js
* import { EmbeddedJWK } from 'https://deno.land/x/jose@VERSION/jwk/embedded.ts'
* ```
*
* @example Usage
* ```js
* import { jwtVerify } from 'jose/jwt/verify'
Expand All @@ -46,7 +49,6 @@ async function EmbeddedJWK(protectedHeader: JWSHeaderParameters, token: Flattene
throw new JWSInvalid('"jwk" (JSON Web Key) Header Parameter must be a JSON object')
}

// eslint-disable-next-line @typescript-eslint/keyword-spacing
const key = <CryptoKey | KeyObject>await parseJwk(joseHeader.jwk!, joseHeader.alg!, true)

if (key.type !== 'public') {
Expand Down
7 changes: 6 additions & 1 deletion src/jwk/from_key_like.ts
Original file line number Diff line number Diff line change
@@ -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'

/**
Expand All @@ -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)
Expand Down
Loading

0 comments on commit 5c7d265

Please sign in to comment.