Skip to content

Commit 07a89bc

Browse files
committed
.
0 parents  commit 07a89bc

13 files changed

+13640
-0
lines changed

.editorconfig

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# EditorConfig is awesome: http://EditorConfig.org
2+
3+
root = true
4+
5+
[*]
6+
indent_size = 2
7+
indent_style = space
8+
end_of_line = lf
9+
charset = utf-8
10+
trim_trailing_whitespace = true
11+
insert_final_newline = true

.eslintrc.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
parser: "@typescript-eslint/parser",
3+
extends: [
4+
"plugin:@typescript-eslint/recommended",
5+
"prettier/@typescript-eslint",
6+
"plugin:prettier/recommended",
7+
],
8+
parserOptions: {
9+
ecmaVersion: 2018,
10+
sourceType: "module",
11+
},
12+
};

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules/
2+
coverage/
3+
.DS_Store
4+
npm-debug.log
5+
dist/
6+
dist.es2015/

.travis.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
language: node_js
2+
3+
notifications:
4+
email:
5+
on_success: never
6+
on_failure: change
7+
8+
node_js:
9+
- "10"
10+
- stable
11+
12+
after_script:
13+
- npm install coveralls@2
14+
- cat ./coverage/lcov.info | coveralls

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2020 Blake Embrey ([email protected])
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Web JWT
2+
3+
[![NPM version][npm-image]][npm-url]
4+
[![NPM downloads][downloads-image]][downloads-url]
5+
[![Build status][travis-image]][travis-url]
6+
[![Test coverage][coveralls-image]][coveralls-url]
7+
[![Bundle size][bundlephobia-image]][bundlephobia-url]
8+
9+
> Small JWT library using the [Web Crypto API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API).
10+
11+
## Installation
12+
13+
```sh
14+
npm install @borderless/web-jwt --save
15+
```
16+
17+
## Usage
18+
19+
```js
20+
import { encodeJwt, decodeJwt, verifyJwt } from "@borderless/web-jwt";
21+
22+
// Create a web crypto key.
23+
const key = crypto.subtle.importKey(
24+
"jwk",
25+
{
26+
kty: "oct",
27+
k: "4Vulge0qgl6janNxYmrYk-sao2wR5tpyKkh_sTLY2CQ",
28+
alg: "HS256",
29+
},
30+
{ name: "HMAC", hash: "SHA-256" },
31+
false,
32+
["sign", "verify"]
33+
);
34+
35+
// Create a JWT and sign using the key.
36+
await encodeJwt(
37+
{
38+
alg: "HS256",
39+
},
40+
{
41+
test: true,
42+
},
43+
key
44+
); //=> "eyJhbGciOiJIUzI1NiJ9.eyJ0ZXN0Ijp0cnVlfQ.pQM0RvgTKjtAC1XmMnCK4vhgGycbg0vVLn0rsiE8BGc"
45+
46+
// Decode the JWT.
47+
const jwt = await decodeJwt(
48+
"eyJhbGciOiJIUzI1NiJ9.eyJ0ZXN0Ijp0cnVlfQ.pQM0RvgTKjtAC1XmMnCK4vhgGycbg0vVLn0rsiE8BGc"
49+
); //=> { header, payload, ... }
50+
51+
// Verify the decoded JWT _before_ trusting!
52+
const valid = await verifyJwt(jwt); //=> true
53+
```
54+
55+
## TypeScript
56+
57+
This project is written using [TypeScript](https://github.com/Microsoft/TypeScript) and publishes the definitions directly to NPM.
58+
59+
## License
60+
61+
MIT
62+
63+
[npm-image]: https://img.shields.io/npm/v/@borderless/web-jwt.svg?style=flat
64+
[npm-url]: https://npmjs.org/package/@borderless/web-jwt
65+
[downloads-image]: https://img.shields.io/npm/dm/@borderless/web-jwt.svg?style=flat
66+
[downloads-url]: https://npmjs.org/package/@borderless/web-jwt
67+
[travis-image]: https://img.shields.io/travis/BorderlessLabs/web-jwt.svg?style=flat
68+
[travis-url]: https://travis-ci.org/BorderlessLabs/web-jwt
69+
[coveralls-image]: https://img.shields.io/coveralls/BorderlessLabs/web-jwt.svg?style=flat
70+
[coveralls-url]: https://coveralls.io/r/BorderlessLabs/web-jwt?branch=master
71+
[bundlephobia-image]: https://img.shields.io/bundlephobia/minzip/@borderless/web-jwt.svg
72+
[bundlephobia-url]: https://bundlephobia.com/result?p=@borderless/web-jwt

jest.setup.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const { TextEncoder, TextDecoder } = require("util");
2+
3+
global.TextEncoder = TextEncoder;
4+
global.TextDecoder = TextDecoder;
5+
global.crypto = require("isomorphic-webcrypto");

0 commit comments

Comments
 (0)