Skip to content
This repository has been archived by the owner on Jun 23, 2019. It is now read-only.

Commit

Permalink
🔧 To fix #1
Browse files Browse the repository at this point in the history
🔥 Minor update to fix #2
  • Loading branch information
motss committed Mar 22, 2018
1 parent 8c54578 commit dde15d2
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 26 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ yarn-error.log*
# folders
./test*/
coverage*/
demo*/
node_modules/

# .js files
Expand Down
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ node_modules/

# .js files
gulpfile*.js

# Do not ignore
!**/json.d.ts
23 changes: 11 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

[![NPM][nodei-badge]][nodei-url]

[![Build Status][travis-badge]][travis-url]
[![Version][version-badge]][version-url]
[![Downloads][downloads-badge]][downloads-url]
[![MIT License][mit-license-badge]][mit-license-url]
[![Code of Conduct][coc-badge]][coc-url]

[![Build Status][travis-badge]][travis-url]
[![Dependency Status][daviddm-badge]][daviddm-url]
[![NSP Status][nsp-badge]][nsp-url]

[![Code of Conduct][coc-badge]][coc-url]
[![codecov][codecov-badge]][codecov-url]
[![Coverage Status][coveralls-badge]][coveralls-url]

Expand Down Expand Up @@ -216,15 +216,14 @@ This methods works the same as `unsign(signature, options)` except that this is
<!-- Badges -->
[nodei-badge]: https://nodei.co/npm/@motss/signatur.png?downloads=true&downloadRank=true&stars=true

[travis-badge]: https://img.shields.io/travis/motss/signatur.svg?style=flat-square

[version-badge]: https://img.shields.io/npm/v/@motss/signatur.svg?style=flat-square
[downloads-badge]: https://img.shields.io/npm/dm/@motss/signatur.svg?style=flat-square
[mit-license-badge]: https://img.shields.io/github/license/mashape/apistatus.svg?style=flat-square
[nsp-badge]: https://nodesecurity.io/orgs/motss/projects/7746c9f7-eefb-4f62-a346-d1c4e3eb43db/badge?style=flat-square
[daviddm-badge]: https://img.shields.io/david/motss/signatur.svg?style=flat-square

[coc-badge]: https://img.shields.io/badge/code%20of-conduct-ff69b4.svg?style=flat-square

[travis-badge]: https://img.shields.io/travis/motss/signatur.svg?style=flat-square
[daviddm-badge]: https://img.shields.io/david/motss/signatur.svg?style=flat-square
[nsp-badge]: https://nodesecurity.io/orgs/motss/projects/7746c9f7-eefb-4f62-a346-d1c4e3eb43db/badge?style=flat-square
[codecov-badge]: https://codecov.io/gh/motss/signatur/branch/master/graph/badge.svg
[coveralls-badge]: https://coveralls.io/repos/github/motss/signatur/badge.svg?branch=master&style=flat-square

Expand All @@ -234,14 +233,14 @@ This methods works the same as `unsign(signature, options)` except that this is
<!-- Links -->
[nodei-url]: https://nodei.co/npm/@motss/signatur

[travis-url]: https://travis-ci.org/motss/signatur
[version-url]: https://npmjs.org/package/@motss/signatur
[downloads-url]: http://www.npmtrends.com/@motss/signatur
[mit-license-url]: https://github.com/motss/signatur/blob/master/LICENSE
[nsp-url]: https://nodesecurity.io/orgs/motss/projects/7746c9f7-eefb-4f62-a346-d1c4e3eb43db
[daviddm-url]: https://david-dm.org/motss/signatur

[coc-url]: https://github.com/motss/signatur/blob/master/CODE_OF_CONDUCT.md

[travis-url]: https://travis-ci.org/motss/signatur
[daviddm-url]: https://david-dm.org/motss/signatur
[nsp-url]: https://nodesecurity.io/orgs/motss/projects/7746c9f7-eefb-4f62-a346-d1c4e3eb43db
[codecov-url]: https://codecov.io/gh/motss/signatur
[coveralls-url]: https://coveralls.io/github/motss/signatur?branch=master

Expand Down
10 changes: 5 additions & 5 deletions gulpfile.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// @ts-check

/** Import project dependencies */
import * as del from 'del';
import * as gulp from 'gulp';
import * as babel from 'gulp-babel';
import * as sq from 'gulp-sequence';
import del from 'del';
import gulp from 'gulp';
import babel from 'gulp-babel';
import sq from 'gulp-sequence';
import lint from 'gulp-tslint';
import * as ts from 'gulp-typescript';
import ts from 'gulp-typescript';
import * as tslint from 'tslint';

/** Setting up */
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@
"build:debug": "npm run ts && gulp build && npm run cleanup",
"check": "npm run lint && npm run nsp",
"cleanup": "rm -rf gulpfile.js",
"demo": "node src/demo/",
"gulp": "npm run ts && gulp",
"lint": "npm run ts && gulp lint && npm run cleanup",
"nsp": "nsp check",
"prepublishOnly": "npm run check && npm run build",
"test": "jest --config ./.jestrc.json",
"ts": "tsc --target esnext --lib esnext,esnext.asynciterable --module commonjs gulpfile.ts"
"ts": "tsc --target esnext --lib esnext,esnext.array,esnext.asynciterable --esModuleInterop --allowSyntheticDefaultImports --module commonjs gulpfile.ts"
},
"dependencies": {},
"devDependencies": {
Expand Down
2 changes: 2 additions & 0 deletions src/demo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Do not ignore
!**/*.js
23 changes: 23 additions & 0 deletions src/demo/cjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// @ts-check

const signatur = require('../../');

void async function main() {
try {
const payload = {
id: 'test-id',
first_name: 'John',
last_name: 'Doe',
timestamp: '2020-02-02T02:20:202',
};
const opts = {
secret: 'test-secret',
};
const enc = await signatur.sign(payload, opts);
const dec = await signatur.unsign(enc, opts);

console.log({ enc, dec });
} catch (e) {
console.error('🔥 ERR', e);
}
}()
30 changes: 30 additions & 0 deletions src/demo/esm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// @ts-check

export default interface Payload {
id: string;
first_name: string;
last_name: string;
timestamp: string;
}

import signatur from '../../';

void async function main() {
try {
const payload: Payload = {
id: 'test-id',
first_name: 'John',
last_name: 'Doe',
timestamp: '2020-02-02T02:20:202',
};
const opts = {
secret: 'test-secret',
};
const enc = await signatur.sign(payload, opts);
const dec = await signatur.unsign<Payload>(enc, opts) as Payload;

console.log({ enc, dec });
} catch (e) {
console.error('🔥 ERR', e);
}
}();
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export declare interface SignaturOptions {
}

/** Import project dependencies */
import * as crypto from 'crypto';
import crypto from 'crypto';

export function urlSafeBase64(s: string) {
return s.replace(/\+/gi, '-')
Expand Down Expand Up @@ -82,9 +82,9 @@ export function unsignSync<T>(
.toString('utf8');
const signedDecoded = urlSafeBase64(
crypto
.createHmac('sha256', secret)
.update(decoded)
.digest('base64')
.createHmac('sha256', secret)
.update(decoded)
.digest('base64')
);

if (enc !== signedDecoded) {
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"allowSyntheticDefaultImports": false,
"allowSyntheticDefaultImports": true,
"allowUnreachableCode": false,
"allowUnusedLabels": true,
"esModuleInterop": true,
Expand All @@ -15,7 +15,7 @@

"lib": ["esnext", "esnext.asynciterable"],
"moduleResolution": "node",
"module": "es2015",
"module": "commonjs",
"target": "esnext",
"jsx": "react",
"jsxFactory": "h",
Expand Down
2 changes: 1 addition & 1 deletion tslint.prod.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"array-type": false,
"import-name": false,
"interface-name": [true, "never-prefix"],
"no-console": true,
"no-console": false,
"no-debugger": true,
"no-duplicate-imports": false,
"no-object-literal-type-assertion": false,
Expand Down

0 comments on commit dde15d2

Please sign in to comment.