@adorsys/jwe-codec
Advanced tools
Comparing version 0.0.2 to 1.0.0
{ | ||
"name": "@adorsys/jwe-codec", | ||
"version": "0.0.2", | ||
"version": "1.0.0", | ||
"description": "Codec to encrypt any javascript value into a JsonWebEncryption (JWE)", | ||
@@ -9,3 +9,3 @@ "main": "src/index.js", | ||
"type": "git", | ||
"url": "git+https://github.com/adorsys/jwe-codec.git" | ||
"url": "https://github.com/adorsys/jwe-codec.git" | ||
}, | ||
@@ -35,11 +35,16 @@ "keywords": [ | ||
"format": "prettier-standard '**/*.js'", | ||
"test": "npm run lint && nyc ava --verbose" | ||
"test": "ava", | ||
"test:cover": "nyc --reporter=lcov ava", | ||
"coverage": "nyc report --reporter=text-lcov | coveralls", | ||
"travis-deploy-once": "travis-deploy-once", | ||
"semantic-release": "semantic-release" | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "lint-staged" | ||
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS", | ||
"pre-commit": "npm run test && lint-staged" | ||
} | ||
}, | ||
"lint-staged": { | ||
"*.js": [ | ||
"{src,test}/**/*.js": [ | ||
"prettier-standard", | ||
@@ -49,2 +54,8 @@ "git add" | ||
}, | ||
"ava": { | ||
"files": [ | ||
"test/**/*.test.js" | ||
], | ||
"verbose": true | ||
}, | ||
"dependencies": { | ||
@@ -55,3 +66,6 @@ "hydration": "1.0.0", | ||
"devDependencies": { | ||
"@commitlint/cli": "7.1.2", | ||
"@commitlint/config-conventional": "7.1.2", | ||
"ava": "1.0.0-beta.8", | ||
"coveralls": "3.0.2", | ||
"eslint-plugin-html": "4.0.5", | ||
@@ -63,5 +77,7 @@ "eslint-plugin-markdown": "1.0.0-beta.6", | ||
"prettier-standard": "8.0.1", | ||
"semantic-release": "^15.9.16", | ||
"snazzy": "8.0.0", | ||
"standard": "12.0.1" | ||
"standard": "12.0.1", | ||
"travis-deploy-once": "^5.0.8" | ||
} | ||
} |
@@ -1,4 +0,91 @@ | ||
# jwe-codec | ||
# :closed_lock_with_key: jwe-codec :closed_lock_with_key: | ||
[![Travis](https://img.shields.io/travis/adorsys/jwe-codec.svg)](https://travis-ci.org/adorsys/jwe-codec) | ||
[![Coveralls](https://img.shields.io/coveralls/adorsys/jwe-codec.svg)](https://coveralls.io/github/adorsys/jwe-codec) | ||
[![npm](https://img.shields.io/npm/v/@adorsys/jwe-codec.svg)](https://www.npmjs.com/package/@adorsys/jwe-codec) | ||
[![npm](https://img.shields.io/npm/dt/@adorsys/jwe-codec.svg)](https://www.npmjs.com/package/@adorsys/jwe-codec) | ||
[![Conventional Commits](https://img.shields.io/badge/Conventional_Commits-1.0.0-yellow.svg)](https://conventionalcommits.org) | ||
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com) | ||
[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier#readme) | ||
[![NpmLicense](https://img.shields.io/npm/l/@adorsys/jwe-codec.svg)](https://github.com/adorsys/jwe-codec/blob/master/LICENSE) | ||
<!-- | ||
[![Dev Dependencies](https://david-dm.org/adorsys/crypto-codecs/dev-status.svg)](https://david-dm.org/adorsys/crypto-codecs?type=dev) | ||
--> | ||
A library for encrypting/decrypting any JavaScript value as JsonWebEncryption (JWE) | ||
### Features | ||
- Promise based interface | ||
- Encrypting/Decrypting anything from (number, string, boolean, array, date, regex, buffer, object) | ||
- TypeScript support | ||
- support for symetric JsonWebKeys { kty: 'oct' } | ||
- supported algorithms 'A256KW', 'A256GCM', 'A256GCMKW' | ||
- Continous integration with [Travis](https://travis-ci.org/adorsys/jwe-codec) | ||
### Installation | ||
```bash | ||
npm install @adorsys/jwe-codec | ||
``` | ||
### Usage | ||
```js | ||
const jwe = require('@adorsys/jwe-codec') | ||
const key = { | ||
kty: 'oct', | ||
alg: 'A256GCM', | ||
use: 'enc', | ||
k: '123456789abcdefghijklmnopqrstuvwxyz12345678' | ||
} | ||
... | ||
``` | ||
#### with async/await | ||
```js | ||
... | ||
;(async () => { | ||
const codec = await jwe(key) | ||
const cipher = await codec.encrypt(42) | ||
// => eyJlbmMiOiJBMjU2R0NNIiwiYWxnIjoiZGlyIiwia2lkIjoialpESEVqN0ZhR3N5OHNUSUZLRWlnejB4TjFEVWlBZWp0S1ZNcEl2Z3dqOCJ9..lipFQHmBiBhsTRqE.4rLjRCOj7JZIKOpToIhOp8cJgvfNWl4Yo__VnkO7yRIYjrCLdGRl5fcR.9S_DwYmkpdLap1yyYYq44A | ||
const answer = await codec.decrypt(cipher) | ||
// => 42 | ||
})() | ||
``` | ||
#### with Promises | ||
```js | ||
... | ||
jwe(key).then(codec => { | ||
codec.encrypt(42).then(cipher => { | ||
codec.decrypt(cipher).then(answer => { | ||
console.log(answer) // 42 | ||
}) | ||
}) | ||
}) | ||
``` | ||
## Credits | ||
Made with :heart: by [radzom](https://github.com/radzom) and all these wonderful contributors ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)): | ||
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --> | ||
<!-- prettier-ignore --> | ||
| <img src="https://avatars.githubusercontent.com/u/1225651?v=3" width="100px;"/><br /><sub><b>Francis Pouatcha</b></sub><br />🤔 | | | | | | | | ||
| :---: | :---: | :---: | :---: | :---: | :---: | :---: | | ||
<!-- ALL-CONTRIBUTORS-LIST:END --> | ||
This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind are welcome! |
export interface JWK { | ||
kty: 'oct', | ||
kid?: string, | ||
alg?: 'A256KW' | 'A256GCM' | 'A256GCMKW', | ||
alg?: 'A256KW' | 'A256GCM' | 'A256GCMKW' | 'A128CBC-HS256', | ||
use?: 'enc', | ||
@@ -6,0 +6,0 @@ k: string |
@@ -7,3 +7,5 @@ const jose = require('node-jose') | ||
['oct'].includes(jwk.kty) && | ||
['A256KW', 'A256GCMKW', 'A256GCM', undefined].includes(jwk.alg) && | ||
['A256KW', 'A256GCMKW', 'A256GCM', 'A128CBC-HS256', undefined].includes( | ||
jwk.alg | ||
) && | ||
['enc', undefined].includes(jwk.use) && | ||
@@ -10,0 +12,0 @@ jwk.k.match(/^[A-Za-z0-9_-]{43}$/) |
const test = require('ava') | ||
const jwe = require('../src') | ||
const validJwk = { | ||
kty: 'oct', | ||
use: 'enc', | ||
alg: 'A256GCM', | ||
k: '1234567890123456789012345678901234567890123' | ||
} | ||
const validJwks = [ | ||
{ | ||
kty: 'oct', | ||
use: 'enc', | ||
alg: 'A256GCM', | ||
k: '1234567890123456789012345678901234567890123' | ||
}, | ||
{ | ||
kty: 'oct', | ||
use: 'enc', | ||
alg: 'A256GCMKW', | ||
k: '1234567890123456789012345678901234567890123' | ||
}, | ||
{ | ||
kty: 'oct', | ||
use: 'enc', | ||
alg: 'A256KW', | ||
k: '1234567890123456789012345678901234567890123' | ||
}, | ||
{ | ||
kty: 'oct', | ||
use: 'enc', | ||
alg: 'A128CBC-HS256', | ||
k: '1234567890123456789012345678901234567890123' | ||
} | ||
] | ||
@@ -79,18 +99,23 @@ const corruptJwks = [ | ||
testValues.forEach((tv, i) => { | ||
test.cb(`encrypt/decrypt ${JSON.stringify(testValues[i])}`, t => { | ||
;(async () => { | ||
const codec = await jwe(validJwk) | ||
const cipher = await codec.encrypt(tv) | ||
t.is(typeof cipher, 'string', 'encrypt gives string') | ||
const parts = cipher.split('.') | ||
t.is(parts.length, 5, 'with 5 parts') | ||
parts.forEach(part => { | ||
t.regex(part, /^[A-Za-z0-9_-]*$/, 'of Base64 encoded values') | ||
}) | ||
const value = await codec.decrypt(cipher) | ||
t.deepEqual(value, tv, 'decrypt gives correct value') | ||
t.end() | ||
})() | ||
validJwks.forEach((jwk, i) => { | ||
testValues.forEach((tv, i) => { | ||
test.cb( | ||
`encrypt/decrypt with ${jwk.alg} ${JSON.stringify(testValues[i])}`, | ||
t => { | ||
;(async () => { | ||
const codec = await jwe(jwk) | ||
const cipher = await codec.encrypt(tv) | ||
t.is(typeof cipher, 'string', 'encrypt gives string') | ||
const parts = cipher.split('.') | ||
t.is(parts.length, 5, 'with 5 parts') | ||
parts.forEach(part => { | ||
t.regex(part, /^[A-Za-z0-9_-]*$/, 'of Base64 encoded values') | ||
}) | ||
const value = await codec.decrypt(cipher) | ||
t.deepEqual(value, tv, 'decrypt gives correct value') | ||
t.end() | ||
})() | ||
} | ||
) | ||
}) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
11158
11
198
0
92
14