cybertoken 2.1.1 → 3.0.2
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/dist/base62.d.ts +4 -0
- package/dist/base62.js +122 -0
- package/{built → dist}/index.js +2 -2
- package/{built → dist}/parse.d.ts +1 -0
- package/{built → dist}/parse.js +3 -2
- package/package.json +4 -7
- package/biome.json +0 -22
- package/built/constants.d.ts +0 -4
- package/built/constants.js +0 -4
- package/built/index.test.d.ts +0 -1
- package/built/parse.test.d.ts +0 -1
- package/jsr.json +0 -5
- /package/{built → dist}/cli.d.ts +0 -0
- /package/{built → dist}/cli.js +0 -0
- /package/{built → dist}/crc32.d.ts +0 -0
- /package/{built → dist}/crc32.js +0 -0
- /package/{built → dist}/index.d.ts +0 -0
package/dist/base62.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
2
|
+
export declare function encode(source: Uint8Array | ArrayBufferView): string;
|
|
3
|
+
export declare function decodeUnsafe(source: string): Uint8Array | undefined;
|
|
4
|
+
export declare function decode(string: string): Uint8Array;
|
package/dist/base62.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
export const alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
2
|
+
const BASE_MAP = new Uint8Array([
|
|
3
|
+
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
|
4
|
+
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
|
5
|
+
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
|
6
|
+
255, 255, 255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 255, 255, 255, 255, 255, 255,
|
|
7
|
+
255, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
|
|
8
|
+
28, 29, 30, 31, 32, 33, 34, 35, 255, 255, 255, 255, 255, 255, 36, 37, 38, 39,
|
|
9
|
+
40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58,
|
|
10
|
+
59, 60, 61, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
|
11
|
+
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
|
12
|
+
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
|
13
|
+
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
|
14
|
+
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
|
15
|
+
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
|
16
|
+
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
|
17
|
+
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
|
18
|
+
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
|
19
|
+
]);
|
|
20
|
+
const BASE = alphabet.length;
|
|
21
|
+
const LEADER = alphabet[0];
|
|
22
|
+
const FACTOR = Math.log(BASE) / Math.log(256);
|
|
23
|
+
const iFACTOR = Math.log(256) / Math.log(BASE);
|
|
24
|
+
export function encode(source) {
|
|
25
|
+
let src;
|
|
26
|
+
if (source instanceof Uint8Array) {
|
|
27
|
+
src = source;
|
|
28
|
+
}
|
|
29
|
+
else if (ArrayBuffer.isView(source)) {
|
|
30
|
+
src = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
throw new Error("`source` has non-supported type. Provide `Uint8Array` or `ArrayBufferView`.");
|
|
34
|
+
}
|
|
35
|
+
if (src.length === 0) {
|
|
36
|
+
return "";
|
|
37
|
+
}
|
|
38
|
+
let zeroes = 0;
|
|
39
|
+
let length = 0;
|
|
40
|
+
let pbegin = 0;
|
|
41
|
+
const pend = src.length;
|
|
42
|
+
while (pbegin !== pend && src[pbegin] === 0) {
|
|
43
|
+
pbegin++;
|
|
44
|
+
zeroes++;
|
|
45
|
+
}
|
|
46
|
+
const size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
|
|
47
|
+
const b58 = new Uint8Array(size);
|
|
48
|
+
while (pbegin !== pend) {
|
|
49
|
+
let carry = src[pbegin];
|
|
50
|
+
let i = 0;
|
|
51
|
+
for (let it1 = size - 1; (carry !== 0 || i < length) && it1 !== -1; it1--, i++) {
|
|
52
|
+
carry += (256 * b58[it1]) >>> 0;
|
|
53
|
+
b58[it1] = (carry % BASE) >>> 0;
|
|
54
|
+
carry = (carry / BASE) >>> 0;
|
|
55
|
+
}
|
|
56
|
+
if (carry !== 0) {
|
|
57
|
+
throw new Error("Non-zero carry");
|
|
58
|
+
}
|
|
59
|
+
length = i;
|
|
60
|
+
pbegin++;
|
|
61
|
+
}
|
|
62
|
+
let it2 = size - length;
|
|
63
|
+
while (it2 !== size && b58[it2] === 0) {
|
|
64
|
+
it2++;
|
|
65
|
+
}
|
|
66
|
+
let str = LEADER.repeat(zeroes);
|
|
67
|
+
for (; it2 < size; ++it2) {
|
|
68
|
+
str += alphabet[b58[it2]];
|
|
69
|
+
}
|
|
70
|
+
return str;
|
|
71
|
+
}
|
|
72
|
+
export function decodeUnsafe(source) {
|
|
73
|
+
if (typeof source !== "string") {
|
|
74
|
+
throw new TypeError("Expected String");
|
|
75
|
+
}
|
|
76
|
+
if (source.length === 0) {
|
|
77
|
+
return new Uint8Array();
|
|
78
|
+
}
|
|
79
|
+
let psz = 0;
|
|
80
|
+
let zeroes = 0;
|
|
81
|
+
let length = 0;
|
|
82
|
+
while (source[psz] === LEADER) {
|
|
83
|
+
zeroes++;
|
|
84
|
+
psz++;
|
|
85
|
+
}
|
|
86
|
+
const size = ((source.length - psz) * FACTOR + 1) >>> 0;
|
|
87
|
+
const b256 = new Uint8Array(size);
|
|
88
|
+
while (source[psz]) {
|
|
89
|
+
let carry = BASE_MAP[source.charCodeAt(psz)];
|
|
90
|
+
if (carry === 255) {
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
let i = 0;
|
|
94
|
+
for (let it3 = size - 1; (carry !== 0 || i < length) && it3 !== -1; it3--, i++) {
|
|
95
|
+
carry += (BASE * b256[it3]) >>> 0;
|
|
96
|
+
b256[it3] = (carry % 256) >>> 0;
|
|
97
|
+
carry = (carry / 256) >>> 0;
|
|
98
|
+
}
|
|
99
|
+
if (carry !== 0) {
|
|
100
|
+
throw new Error("Non-zero carry");
|
|
101
|
+
}
|
|
102
|
+
length = i;
|
|
103
|
+
psz++;
|
|
104
|
+
}
|
|
105
|
+
let it4 = size - length;
|
|
106
|
+
while (it4 !== size && b256[it4] === 0) {
|
|
107
|
+
it4++;
|
|
108
|
+
}
|
|
109
|
+
const vch = new Uint8Array(zeroes + (size - it4));
|
|
110
|
+
let j = zeroes;
|
|
111
|
+
while (it4 !== size) {
|
|
112
|
+
vch[j++] = b256[it4++];
|
|
113
|
+
}
|
|
114
|
+
return vch;
|
|
115
|
+
}
|
|
116
|
+
export function decode(string) {
|
|
117
|
+
const buffer = decodeUnsafe(string);
|
|
118
|
+
if (buffer) {
|
|
119
|
+
return buffer;
|
|
120
|
+
}
|
|
121
|
+
throw new Error("Failed to decode string");
|
|
122
|
+
}
|
package/{built → dist}/index.js
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { base62, version } from "./constants.js";
|
|
2
1
|
import crc32 from "./crc32.js";
|
|
3
|
-
import
|
|
2
|
+
import * as base62 from "./base62.js";
|
|
3
|
+
import { getTokenPattern, parseTokenData, version } from "./parse.js";
|
|
4
4
|
const cryptoServices = globalThis.crypto;
|
|
5
5
|
export function createTokenGenerator(options) {
|
|
6
6
|
var _a;
|
package/{built → dist}/parse.js
RENAMED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { alphabet, base62, version } from "./constants.js";
|
|
2
1
|
import crc32 from "./crc32.js";
|
|
2
|
+
import * as base62 from "./base62.js";
|
|
3
|
+
export const version = 0;
|
|
3
4
|
export function getTokenPattern(prefixWithUnderscore) {
|
|
4
|
-
return new RegExp(`^${prefixWithUnderscore}[${alphabet}]+$`);
|
|
5
|
+
return new RegExp(`^${prefixWithUnderscore}[${base62.alphabet}]+$`);
|
|
5
6
|
}
|
|
6
7
|
export function parseTokenData(token) {
|
|
7
8
|
if (!token.includes("_")) {
|
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cybertoken",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.2",
|
|
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
|
-
"main": "
|
|
9
|
-
"bin": "
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"bin": "dist/cli.js",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
12
|
"url": "https://github.com/nikeee/cybertoken.git"
|
|
13
13
|
},
|
|
14
14
|
"scripts": {
|
|
15
15
|
"compile": "tsc",
|
|
16
|
-
"clean": "rimraf
|
|
16
|
+
"clean": "rimraf dist",
|
|
17
17
|
"ci": "tsc --noEmit && biome ci ./src",
|
|
18
18
|
"docs": "typedoc",
|
|
19
19
|
"format": "biome format --write ./src",
|
|
@@ -29,9 +29,6 @@
|
|
|
29
29
|
"secret",
|
|
30
30
|
"generator"
|
|
31
31
|
],
|
|
32
|
-
"dependencies": {
|
|
33
|
-
"base-x": "^5.0.0"
|
|
34
|
-
},
|
|
35
32
|
"devDependencies": {
|
|
36
33
|
"@biomejs/biome": "^1.9.4",
|
|
37
34
|
"@types/node": "^22.10.10",
|
package/biome.json
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://biomejs.dev/schemas/1.5.3/schema.json",
|
|
3
|
-
"organizeImports": {
|
|
4
|
-
"enabled": true
|
|
5
|
-
},
|
|
6
|
-
"vcs": {
|
|
7
|
-
"enabled": true,
|
|
8
|
-
"clientKind": "git",
|
|
9
|
-
"useIgnoreFile": true
|
|
10
|
-
},
|
|
11
|
-
"linter": {
|
|
12
|
-
"enabled": true,
|
|
13
|
-
"rules": {
|
|
14
|
-
"recommended": true
|
|
15
|
-
}
|
|
16
|
-
},
|
|
17
|
-
"javascript": {
|
|
18
|
-
"formatter": {
|
|
19
|
-
"arrowParentheses": "asNeeded"
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
package/built/constants.d.ts
DELETED
package/built/constants.js
DELETED
package/built/index.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/built/parse.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/jsr.json
DELETED
/package/{built → dist}/cli.d.ts
RENAMED
|
File without changes
|
/package/{built → dist}/cli.js
RENAMED
|
File without changes
|
|
File without changes
|
/package/{built → dist}/crc32.js
RENAMED
|
File without changes
|
|
File without changes
|