Skip to content

Commit

Permalink
fix(build): non-minified outputs and better handling of strict mode (#…
Browse files Browse the repository at this point in the history
…175)

* fix(build): produce non-minified output for module

fixes #173

* fix(build): fix strict compiler errors for most of the code

fixes #174

* chore(ci): adjust bot schedule for less noise

* fix(style): enable strict mode and fix strict compiler errors

* chore(style): enable eslint and fix linter errors

* chore: clarify usage of JWK epk and proof types for signing
  • Loading branch information
mirceanis committed Jun 2, 2021
1 parent 59ec030 commit 029b429
Show file tree
Hide file tree
Showing 15 changed files with 1,063 additions and 1,234 deletions.
17 changes: 14 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
module.exports = {
extends: 'standard',
plugins: ['jest'],
env: {
node: true,
'jest/globals': true
}
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended'
],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module'
},
plugins: ['@typescript-eslint', 'jest'],
rules: {}
}
10 changes: 7 additions & 3 deletions stale.yml → .github/stale.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# Number of days of inactivity before an issue becomes stale
daysUntilStale: 60
daysUntilStale: 70
# Number of days of inactivity before a stale issue is closed
daysUntilClose: 7
daysUntilClose: 14
# Issues with these labels will never be considered stale
exemptLabels:
- pinned
- security
- in-progress
- planned-feature
- good-first-issue
- triage
# Label to use when marking an issue as stale
staleLabel: wontfix
staleLabel: stale
# Comment to post when marking an issue as stale. Set to `false` to disable
markComment: >
This issue has been automatically marked as stale because it has not had
Expand Down
66 changes: 25 additions & 41 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
{
"name": "did-jwt",
"version": "5.5.0",
"description": "Library for Signing and Verifying JWTs compatible uPort and DID standards",
"main": "lib/index.js",
"description": "Library for Signing and Verifying JWTs that use DIDs as issuers and JWEs that use DIDs as recipients",
"source": "src/index.ts",
"modules": "lib/index.mjs",
"types": "lib/index.d.ts",
"umd:main": "lib/index.umd.js",
"main": "./lib/index.js",
"exports": "./lib/index.modern.js",
"module": "./lib/index.module.js",
"unpkg": "./lib/index.umd.js",
"types": "./lib/index.d.ts",
"umd:main": "./lib/index.umd.js",
"files": [
"lib",
"dist",
"src",
"tutorial",
"esm"
"src"
],
"scripts": {
"test": "jest",
"test:ci": "jest --coverage && codecov",
"build:js": "microbundle",
"build:js": "microbundle --compress=false",
"build:browser": "webpack --config webpack.config.js",
"build": "npm run build:js && npm test && npm run build:browser",
"build": "yarn build:js && yarn test && yarn build:browser",
"build:docs": "echo 'PLEASE UPDATE REFERENCE DOCS MANUALLY'",
"format": "prettier --write \"src/**/*.ts\"",
"lint": "standard && tslint -p tsconfig.json",
"prepublishOnly": "npm test && npm run lint",
"prepare": "npm run build",
"lint": "eslint src/ --ext .ts",
"prepublishOnly": "yarn test && yarn lint",
"prepare": "yarn build",
"release": "semantic-release --debug"
},
"author": "Pelle Braendgaard <pelle.braendgaard@consensys.net>",
"author": "Pelle Braendgaard",
"contributors": [
"Mircea Nistor <mircea.nistor@consensys.net>",
"Mircea Nistor <mircea.nistor@mesh.xyz>",
"Oliver Terbu <oliver.terbu@mesh.xyz>",
"Joel Thorstensson <oed@3box.io>"
],
"repository": {
Expand All @@ -51,32 +52,27 @@
]
},
"devDependencies": {
"@babel/core": "7.14.3",
"@babel/preset-env": "7.14.4",
"@babel/preset-typescript": "7.13.0",
"@semantic-release/changelog": "5.0.1",
"@semantic-release/git": "9.0.0",
"@types/elliptic": "6.4.12",
"@types/jest": "26.0.23",
"@typescript-eslint/eslint-plugin": "4.25.0",
"@typescript-eslint/parser": "4.25.0",
"codecov": "3.8.2",
"eslint": "7.27.0",
"eslint-config-standard": "16.0.3",
"eslint-plugin-import": "2.23.4",
"eslint-config-prettier": "8.3.0",
"eslint-plugin-jest": "24.3.6",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-promise": "5.1.0",
"eslint-plugin-standard": "5.0.0",
"eslint-plugin-prettier": "3.4.0",
"jest": "27.0.3",
"jsontokens": "3.0.0",
"microbundle": "0.13.1",
"mockdate": "3.0.5",
"prettier": "2.3.0",
"regenerator-runtime": "0.13.7",
"semantic-release": "17.4.3",
"sinon": "11.1.1",
"standard": "16.0.3",
"ts-jest": "27.0.2",
"tslint": "6.1.3",
"tslint-config-prettier": "1.18.0",
"tslint-eslint-rules": "5.4.0",
"tweetnacl": "1.0.3",
"typescript": "4.3.2",
"webpack": "5.38.1",
Expand All @@ -94,19 +90,7 @@
"js-sha3": "^0.8.0",
"uint8arrays": "^2.1.3"
},
"standard": {
"ignore": [
"lib/**"
],
"globals": [
"it",
"describe",
"expect",
"jest",
"beforeAll",
"beforeEach",
"afterAll",
"afterEach"
]
}
"eslintIgnore": [
"*.test.ts"
]
}
45 changes: 23 additions & 22 deletions renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,33 @@
"config:base",
"group:allNonMajor"
],
"labels": ["maintenance"],
"labels": [
"maintenance"
],
"automergeType": "branch",
"automerge": true,
"packageRules": [
{
"packagePatterns": [ "jest", "sinon", "codecov", "lint", "jsdoc", "bundle", "prettier", "webpack", "typescript" ],
"groupName": "builders-and-testers",
"automerge": true,
"automergeType": "branch",
"schedule": ["before 5am"]
},
{
"packagePatterns": [ "semantic", "commitlint" ],
"groupName": "automation",
"automerge": true,
"automergeType": "branch",
"schedule": ["before 5am"]
"matchPackagePatterns": [
"did"
],
"matchUpdateTypes": [
"bump",
"patch",
"minor",
"major"
],
"groupName": "did-dependencies",
"commitMessagePrefix": "fix(deps):"
},
{
"depTypeList": ["devDependencies"],
"matchDepTypes": [
"devDependencies"
],
"groupName": "devDeps",
"automerge": true,
"automergeType": "branch",
"schedule": ["before 5am"]
},
{
"updateTypes": ["minor", "patch"],
"automerge": true
"schedule": [
"before 5am on Monday"
]
}
]
}
}
38 changes: 27 additions & 11 deletions src/JWE.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
import { base64ToBytes, bytesToBase64url, decodeBase64url, toSealed } from './util'

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type ProtectedHeader = Record<string, any>

/**
* The JWK representation of an ephemeral public key.
* See https://www.rfc-editor.org/rfc/rfc7518.html#section-6
*/
interface EphemeralPublicKey {
kty?: string
//ECC
crv?: string
x?: string
y?: string
//RSA
n?: string
e?: string
}

interface RecipientHeader {
alg: string
iv: string
tag: string
epk?: Record<string, any> // Ephemeral Public Key
epk?: EphemeralPublicKey
kid?: string
apv?: string
apu?: string
Expand Down Expand Up @@ -36,19 +54,14 @@ export interface EncryptionResult {
export interface Encrypter {
alg: string
enc: string
encrypt: (cleartext: Uint8Array, protectedHeader: Record<string, any>, aad?: Uint8Array) => Promise<EncryptionResult>
encrypt: (cleartext: Uint8Array, protectedHeader: ProtectedHeader, aad?: Uint8Array) => Promise<EncryptionResult>
encryptCek?: (cek: Uint8Array) => Promise<Recipient>
}

export interface Decrypter {
alg: string
enc: string
decrypt: (
sealed: Uint8Array,
iv: Uint8Array,
aad?: Uint8Array,
recipient?: Record<string, any>
) => Promise<Uint8Array>
decrypt: (sealed: Uint8Array, iv: Uint8Array, aad?: Uint8Array, recipient?: Recipient) => Promise<Uint8Array | null>
}

function validateJWE(jwe: JWE) {
Expand All @@ -66,7 +79,7 @@ function validateJWE(jwe: JWE) {

function encodeJWE({ ciphertext, tag, iv, protectedHeader, recipient }: EncryptionResult, aad?: Uint8Array): JWE {
const jwe: JWE = {
protected: protectedHeader,
protected: <string>protectedHeader,
iv: bytesToBase64url(iv),
ciphertext: bytesToBase64url(ciphertext),
tag: bytesToBase64url(tag)
Expand Down Expand Up @@ -99,10 +112,13 @@ export async function createJWE(
cek = encryptionResult.cek
jwe = encodeJWE(encryptionResult, aad)
} else {
jwe.recipients.push(await encrypter.encryptCek(cek))
const recipient = await encrypter.encryptCek?.(cek)
if (recipient) {
jwe?.recipients?.push(recipient)
}
}
}
return jwe
return <JWE>jwe
}
}

Expand Down
Loading

0 comments on commit 029b429

Please sign in to comment.