jssign 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,10 @@
1
- declare function sign(data: any, secret: string, { expiresIn, sl }?: {
1
+ declare function sign(data: any, secret: string, { expiresIn, sl }?: Partial<{
2
2
  expiresIn: number;
3
3
  sl: number;
4
- }): string;
4
+ }>): string;
5
5
  declare function verify(token: string, secret: string): any;
6
- declare function encrypt(data: any, secret: string, { expiresIn }?: {
6
+ declare function encrypt(data: any, secret: string, { expiresIn }?: Partial<{
7
7
  expiresIn: number;
8
- }): string;
8
+ }>): string;
9
9
  declare function decrypt(token: string, secret: string): any;
10
10
  export { sign, verify, encrypt, decrypt };
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.decrypt = exports.encrypt = exports.verify = exports.sign = void 0;
7
7
  const sjcl_1 = __importDefault(require("sjcl"));
8
8
  const defaults = { v: 1, iter: 10000, ks: 128, ts: 64, mode: "ccm", adata: "", cipher: "aes" };
9
- const characters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '-', '/', '*', '~', '!', '@', '#', '$', '%', '^', '&'];
9
+ const characters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '`', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '[', ']', ';', ',', '.', '/', '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '{', '}', ':', '<', '>', '?'];
10
10
  const encoder = new TextEncoder();
11
11
  const decoder = new TextDecoder();
12
12
  const randomNumber = (min, max) => min + Math.floor(Math.random() * (max - min + 1));
@@ -48,7 +48,7 @@ function decode(token, secret, type) {
48
48
  decodedBytes[i] = tokenBytes[i] ^ secretBytes[i % secretLength];
49
49
  return decoder.decode(decodedBytes);
50
50
  }
51
- function sign(data, secret, { expiresIn = 0, sl = 8 } = { expiresIn: 0, sl: 8 }) {
51
+ function sign(data, secret, { expiresIn = 0, sl = 32 } = {}) {
52
52
  const salt = genSalt(sl);
53
53
  const token = encode(JSON.stringify({ data, iat: Date.now(), exp: expiresIn }), salt, 1);
54
54
  const signature = encode(salt, secret, 0);
@@ -69,7 +69,7 @@ function verify(token, secret) {
69
69
  }
70
70
  }
71
71
  exports.verify = verify;
72
- function encrypt(data, secret, { expiresIn = 0 } = { expiresIn: 0 }) {
72
+ function encrypt(data, secret, { expiresIn = 0 } = {}) {
73
73
  const { ct, iv, salt } = JSON.parse(sjcl_1.default.encrypt(secret, JSON.stringify({ data, iat: Date.now(), exp: expiresIn })));
74
74
  return `${ct}.${iv}.${salt}`;
75
75
  }
@@ -1,10 +1,10 @@
1
- declare function sign(data: any, secret: string, { expiresIn, sl }?: {
1
+ declare function sign(data: any, secret: string, { expiresIn, sl }?: Partial<{
2
2
  expiresIn: number;
3
3
  sl: number;
4
- }): string;
4
+ }>): string;
5
5
  declare function verify(token: string, secret: string): any;
6
- declare function encrypt(data: any, secret: string, { expiresIn }?: {
6
+ declare function encrypt(data: any, secret: string, { expiresIn }?: Partial<{
7
7
  expiresIn: number;
8
- }): string;
8
+ }>): string;
9
9
  declare function decrypt(token: string, secret: string): any;
10
10
  export { sign, verify, encrypt, decrypt };
@@ -1,6 +1,6 @@
1
1
  import sjcl from 'sjcl';
2
2
  const defaults = { v: 1, iter: 10000, ks: 128, ts: 64, mode: "ccm", adata: "", cipher: "aes" };
3
- const characters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '-', '/', '*', '~', '!', '@', '#', '$', '%', '^', '&'];
3
+ const characters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '`', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '[', ']', ';', ',', '.', '/', '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '{', '}', ':', '<', '>', '?'];
4
4
  const encoder = new TextEncoder();
5
5
  const decoder = new TextDecoder();
6
6
  const randomNumber = (min, max) => min + Math.floor(Math.random() * (max - min + 1));
@@ -42,7 +42,7 @@ function decode(token, secret, type) {
42
42
  decodedBytes[i] = tokenBytes[i] ^ secretBytes[i % secretLength];
43
43
  return decoder.decode(decodedBytes);
44
44
  }
45
- function sign(data, secret, { expiresIn = 0, sl = 8 } = { expiresIn: 0, sl: 8 }) {
45
+ function sign(data, secret, { expiresIn = 0, sl = 32 } = {}) {
46
46
  const salt = genSalt(sl);
47
47
  const token = encode(JSON.stringify({ data, iat: Date.now(), exp: expiresIn }), salt, 1);
48
48
  const signature = encode(salt, secret, 0);
@@ -61,7 +61,7 @@ function verify(token, secret) {
61
61
  throw new Error('Invalid token or secret!');
62
62
  }
63
63
  }
64
- function encrypt(data, secret, { expiresIn = 0 } = { expiresIn: 0 }) {
64
+ function encrypt(data, secret, { expiresIn = 0 } = {}) {
65
65
  const { ct, iv, salt } = JSON.parse(sjcl.encrypt(secret, JSON.stringify({ data, iat: Date.now(), exp: expiresIn })));
66
66
  return `${ct}.${iv}.${salt}`;
67
67
  }
package/package.json CHANGED
@@ -1,40 +1,40 @@
1
- {
2
- "name": "jssign",
3
- "version": "0.2.0",
4
- "description": "A token generator library to encode and decode data using a secret key",
5
- "main": "./build/cjs/index.js",
6
- "module": "./build/esm/index.js",
7
- "scripts": {
8
- "esm": "tsc",
9
- "cjs": "tsc --module commonjs --outDir build/cjs",
10
- "build": "npm i && npm run esm && npm run cjs"
11
- },
12
- "repository": {
13
- "type": "git",
14
- "url": "git+https://github.com/SahilAggarwal2004/jssign.git"
15
- },
16
- "keywords": [
17
- "jssign",
18
- "jss",
19
- "javascript",
20
- "sign",
21
- "javascriptsign",
22
- "token",
23
- "encryption",
24
- "decryption",
25
- "jsonwebtoken",
26
- "sjcl"
27
- ],
28
- "author": "Sahil Aggarwal",
29
- "license": "MIT",
30
- "bugs": {
31
- "url": "https://github.com/SahilAggarwal2004/jssign/issues"
32
- },
33
- "homepage": "https://github.com/SahilAggarwal2004/jssign#readme",
34
- "dependencies": {
35
- "sjcl": "^1.0.8"
36
- },
37
- "devDependencies": {
38
- "@types/sjcl": "^1.0.30"
39
- }
40
- }
1
+ {
2
+ "name": "jssign",
3
+ "version": "0.2.1",
4
+ "description": "A token generator library to encode and decode data using a secret key",
5
+ "main": "./build/cjs/index.js",
6
+ "module": "./build/esm/index.js",
7
+ "scripts": {
8
+ "esm": "tsc",
9
+ "cjs": "tsc --module commonjs --outDir build/cjs",
10
+ "build": "npm i && npm run esm && npm run cjs"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/SahilAggarwal2004/jssign.git"
15
+ },
16
+ "keywords": [
17
+ "jssign",
18
+ "jss",
19
+ "javascript",
20
+ "sign",
21
+ "javascriptsign",
22
+ "token",
23
+ "encryption",
24
+ "decryption",
25
+ "jsonwebtoken",
26
+ "sjcl"
27
+ ],
28
+ "author": "Sahil Aggarwal",
29
+ "license": "MIT",
30
+ "bugs": {
31
+ "url": "https://github.com/SahilAggarwal2004/jssign/issues"
32
+ },
33
+ "homepage": "https://github.com/SahilAggarwal2004/jssign#readme",
34
+ "dependencies": {
35
+ "sjcl": "^1.0.8"
36
+ },
37
+ "devDependencies": {
38
+ "@types/sjcl": "^1.0.30"
39
+ }
40
+ }