cybertoken 1.0.6 → 2.0.0
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.
- package/README.md +1 -1
- package/built/index.js +1 -2
- package/package.json +12 -5
- package/built/index.test.js +0 -64
- package/built/parse.test.js +0 -35
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# cybertoken [](https://github.com/nikeee/cybertoken/actions/workflows/CI.yaml) [](https://github.com/nikeee/cybertoken/actions/workflows/CI.yaml) [](https://www.npmjs.com/package/cybertoken)
|
|
2
2
|
|
|
3
|
-
A token format inspired by
|
|
3
|
+
A token format inspired by GitHub's new API token format. Think of it as a standardized password format with some handy properties. Intended for API token and password generation.
|
|
4
4
|
|
|
5
5
|
## What is this?
|
|
6
6
|
|
package/built/index.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
var _a;
|
|
2
1
|
import crc32 from "./crc32.js";
|
|
3
2
|
import { base62, version } from "./constants.js";
|
|
4
3
|
import { getTokenPattern, parseTokenData } from "./parse.js";
|
|
5
|
-
const cryptoServices =
|
|
4
|
+
const cryptoServices = globalThis.crypto;
|
|
6
5
|
export function createTokenGenerator(options) {
|
|
7
6
|
var _a;
|
|
8
7
|
if (!options.prefixWithoutUnderscore) {
|
package/package.json
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cybertoken",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "A token format for APIs inspired by the GitHub's API token format.",
|
|
5
5
|
"author": "Niklas Mollenhauer",
|
|
6
6
|
"license": "ISC",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "built/index.js",
|
|
9
9
|
"bin": "built/cli.js",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/nikeee/cybertoken.git"
|
|
13
|
+
},
|
|
10
14
|
"scripts": {
|
|
11
15
|
"compile": "tsc",
|
|
12
16
|
"clean": "rimraf built",
|
|
@@ -27,9 +31,12 @@
|
|
|
27
31
|
"base-x": "^4.0.0"
|
|
28
32
|
},
|
|
29
33
|
"devDependencies": {
|
|
30
|
-
"@vitest/coverage-
|
|
31
|
-
"rimraf": "^
|
|
32
|
-
"typedoc": "^0.
|
|
33
|
-
"vitest": "^0.
|
|
34
|
+
"@vitest/coverage-v8": "^0.34.6",
|
|
35
|
+
"rimraf": "^5.0.5",
|
|
36
|
+
"typedoc": "^0.25.1",
|
|
37
|
+
"vitest": "^0.34.6"
|
|
38
|
+
},
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=20.0.0"
|
|
34
41
|
}
|
|
35
42
|
}
|
package/built/index.test.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { test, expect } from "vitest";
|
|
11
|
-
import { createTokenGenerator } from "./index.js";
|
|
12
|
-
test("Instance creation smoke test", () => {
|
|
13
|
-
createTokenGenerator({
|
|
14
|
-
prefixWithoutUnderscore: "test",
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
test("Instance creation expect prefix", () => {
|
|
18
|
-
expect(() => createTokenGenerator({})).toThrowError("The `prefixWithoutUnderscore` option is required and must not be an empty string.");
|
|
19
|
-
});
|
|
20
|
-
test("Instance creation expect proper byte count", () => {
|
|
21
|
-
expect(() => createTokenGenerator({
|
|
22
|
-
prefixWithoutUnderscore: "a",
|
|
23
|
-
entropyBytes: -1,
|
|
24
|
-
})).toThrowError("The token secret byte count (`entropyBytes`) must be greater than 20.");
|
|
25
|
-
expect(() => createTokenGenerator({
|
|
26
|
-
prefixWithoutUnderscore: "a",
|
|
27
|
-
entropyBytes: 0,
|
|
28
|
-
})).toThrowError("The token secret byte count (`entropyBytes`) must be greater than 20.");
|
|
29
|
-
expect(() => createTokenGenerator({
|
|
30
|
-
prefixWithoutUnderscore: "a",
|
|
31
|
-
entropyBytes: 19,
|
|
32
|
-
})).toThrowError("The token secret byte count (`entropyBytes`) must be greater than 20.");
|
|
33
|
-
expect(() => createTokenGenerator({
|
|
34
|
-
prefixWithoutUnderscore: "a",
|
|
35
|
-
entropyBytes: 20,
|
|
36
|
-
})).toThrowError("The token secret byte count (`entropyBytes`) must be greater than 20.");
|
|
37
|
-
createTokenGenerator({
|
|
38
|
-
prefixWithoutUnderscore: "a",
|
|
39
|
-
entropyBytes: 21,
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
test("Roundtrip syntax check", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
-
const g = createTokenGenerator({ prefixWithoutUnderscore: "test" });
|
|
44
|
-
const token = yield g.generateToken();
|
|
45
|
-
expect(g.isTokenString(token)).toBe(true);
|
|
46
|
-
}));
|
|
47
|
-
test("Non-happy paths in isTokenString", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
48
|
-
const g = createTokenGenerator({ prefixWithoutUnderscore: "test" });
|
|
49
|
-
expect(g.isTokenString()).toBe(false);
|
|
50
|
-
expect(g.isTokenString(null)).toBe(false);
|
|
51
|
-
expect(g.isTokenString(undefined)).toBe(false);
|
|
52
|
-
expect(g.isTokenString("")).toBe(false);
|
|
53
|
-
expect(g.isTokenString("a")).toBe(false);
|
|
54
|
-
expect(g.isTokenString("a_")).toBe(false);
|
|
55
|
-
expect(g.isTokenString("a_1234")).toBe(false);
|
|
56
|
-
expect(g.isTokenString("test_")).toBe(false);
|
|
57
|
-
expect(g.isTokenString("test_1234")).toBe(false);
|
|
58
|
-
expect(g.isTokenString("test_")).toBe(false);
|
|
59
|
-
expect(g.isTokenString("test_AAAABBBB")).toBe(false);
|
|
60
|
-
expect(g.isTokenString("test_R67NJs98Lvg5o42CanYRTirswpki3SAsJYbN")).toBe(false);
|
|
61
|
-
expect(g.isTokenString("test_R67NJs98Lvg5o42CanYRTirswpki3SAsJYbNiDwHd")).toBe(false);
|
|
62
|
-
expect(g.isTokenString("test_R67NJs98Lvg5o42CanYRTirswpki3SAsJYbNiDwHdKNhiyW")).toBe(false);
|
|
63
|
-
expect(g.isTokenString("test_R67NJs98Lvg5o42CanYRTirswpki3SAsJYbNiDwHdKNhiyw")).toBe(true);
|
|
64
|
-
}));
|
package/built/parse.test.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { test, expect } from "vitest";
|
|
2
|
-
import { parseTokenData } from "./parse.js";
|
|
3
|
-
test("Parse token contents", () => {
|
|
4
|
-
let contents;
|
|
5
|
-
contents = parseTokenData("test_R67NJs98Lvg5o42CanYRTirswpki3SAsJYbNiDwHd");
|
|
6
|
-
expect(contents).toBeUndefined();
|
|
7
|
-
contents = parseTokenData("test_");
|
|
8
|
-
expect(contents).toBeUndefined();
|
|
9
|
-
contents = parseTokenData("test_abc_def");
|
|
10
|
-
expect(contents).toBeUndefined();
|
|
11
|
-
contents = parseTokenData("test_R67NJs98Lvg5o42CanYRTirswpki3SAsJYbNiDwHdKNhiyw");
|
|
12
|
-
expect(contents).toEqual({
|
|
13
|
-
prefixWithoutUnderscore: "test",
|
|
14
|
-
actualChecksum: new Uint8Array([94, 199, 163, 74]),
|
|
15
|
-
isSyntacticallyValid: true,
|
|
16
|
-
secret: new Uint8Array([
|
|
17
|
-
100, 166, 3, 29, 89, 224, 104, 216, 82, 241, 34, 139, 193, 245, 62, 254,
|
|
18
|
-
71, 254, 26, 57, 131, 99, 11, 222, 170, 63, 150, 82, 53, 165,
|
|
19
|
-
]),
|
|
20
|
-
suppliedChecksum: new Uint8Array([94, 199, 163, 74]),
|
|
21
|
-
version: 0,
|
|
22
|
-
});
|
|
23
|
-
contents = parseTokenData("randomToken_R67NJs98Lvg5o42CanYRTirswpki3SAsJYbNiDwHdKNhiyw");
|
|
24
|
-
expect(contents).toEqual({
|
|
25
|
-
prefixWithoutUnderscore: "randomToken",
|
|
26
|
-
actualChecksum: new Uint8Array([94, 199, 163, 74]),
|
|
27
|
-
isSyntacticallyValid: true,
|
|
28
|
-
secret: new Uint8Array([
|
|
29
|
-
100, 166, 3, 29, 89, 224, 104, 216, 82, 241, 34, 139, 193, 245, 62, 254,
|
|
30
|
-
71, 254, 26, 57, 131, 99, 11, 222, 170, 63, 150, 82, 53, 165,
|
|
31
|
-
]),
|
|
32
|
-
suppliedChecksum: new Uint8Array([94, 199, 163, 74]),
|
|
33
|
-
version: 0,
|
|
34
|
-
});
|
|
35
|
-
});
|