Skip to content

Commit 6f622ce

Browse files
committed
Add token generation
1 parent 496cd56 commit 6f622ce

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+3573
-123
lines changed

.editorconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ indent_style = space
55
indent_size = 2
66
charset = utf-8
77
trim_trailing_whitespace = true
8-
insert_final_newline = false
8+
insert_final_newline = true

.eslintrc

+3-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"templateStrings": true,
3434
"superInFunctions": true,
3535
"unicodeCodePointEscapes": true,
36+
"experimentalObjectRestSpread": true,
3637
"objectLiteralShorthandMethods": true,
3738
"objectLiteralComputedProperties": true,
3839
"objectLiteralDuplicateProperties": true,
@@ -42,7 +43,7 @@
4243
"plugins": [],
4344
"rules": {
4445
"semi": "warn",
45-
"indent": [ 0, 2 ],
46+
"indent": [ "off", "error" ],
4647
"strict": "off",
4748
"eqeqeq": "error",
4849
"no-var": "warn",
@@ -62,4 +63,4 @@
6263
"_config": false,
6364
"console": false
6465
}
65-
}
66+
}

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
node_modules/
2-
dist/

.vscode/settings.json

+92-22
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,43 @@
11
/*
2-
General vscode settings for all my projects
3-
Made by Wessel "wesselgame" T <discord@go2it.eu> (https://github.com/PassTheWessel)
2+
/ General vscode settings for all my projects
3+
/ Made by Wessel "wesselgame" T <discord@go2it.eu> (https://github.com/PassTheWessel)
44

5-
Extensions: rainglow, eslint, tslint, material icon theme, gitlens, fish-vscode, Docker,
6-
Popping and Locking theme, Sass, stylelint, SVG viewer, Trailing spaces, Auto renaming tags
5+
? Extensions: rainglow, eslint, material icon theme, gitlens, fish-vscode, Docker, EditorConfig for VS Code
6+
? Popping and Locking theme, Sass, stylelint, SVG viewer, Trailing spaces, Auto renaming tags, Better Comments,
7+
? Regex previewer
78

8-
Color themes: Banner (rainglow), Hyrule (rainglow), Azure (rainglow), Github (rainglow),
9-
Heroku (rainglow), Popping and Locking
9+
* Color themes: Banner (rainglow), Hyrule (rainglow), Azure (rainglow), Github (rainglow),
10+
* Heroku (rainglow), Popping and Locking
11+
12+
* Comment legend:
13+
/ Info
14+
* Note
15+
? Question
16+
! Somenthing's wrong
17+
> Changed
18+
+ Added
19+
- Removed
20+
todo TODO
1021
*/
1122
{
12-
// Window
23+
// ? Window - the window options
1324
"window.zoomLevel": 0,
14-
// Editor
25+
// ? Editor - the text editor config
1526
"editor.fontSize": 13,
1627
"editor.fontWeight": "200",
17-
"editor.fontFamily": "'SFMono-Regular','Consolas','Liberation Mono','Menlo','Courier','monospace'",
28+
"editor.fontFamily": "'SFMono-Regular','Consolas','Liberation Mono','Menlo','Courier','monospace','Operator Mono SSm Lig','OperatorMonoSSmLig-Book'",
1829
"editor.lineHeight": 20,
19-
"editor.fontLigatures": true,
2030
"editor.cursorStyle": "line",
31+
"editor.lineNumbers": "relative",
2132
"editor.cursorWidth": 0,
33+
"editor.fontLigatures": true,
2234
"editor.cursorBlinking": "blink",
23-
"editor.multiCursorModifier": "ctrlCmd",
2435
"editor.minimap.enabled": true,
2536
"editor.smoothScrolling": true,
37+
"editor.multiCursorModifier": "ctrlCmd",
2638
"editor.minimap.renderCharacters": true,
2739
"editor.tabSize": 2,
28-
"editor.autoIndent": false,
40+
"editor.autoIndent": true,
2941
"editor.insertSpaces": true,
3042
"editor.tabCompletion": "on",
3143
"editor.formatOnPaste": true,
@@ -43,18 +55,19 @@
4355
"variables": "#C55F45",
4456
"functions": "#C59F55"
4557
},
46-
//Workbench
58+
// ? Workbench - the general working area
4759
"workbench.iconTheme": "material-icon-theme",
48-
"workbench.colorTheme": "Banner (rainglow)",
60+
"workbench.colorTheme": "Darkside (rainglow)",
4961
"workbench.editor.showTabs": true,
62+
"workbench.statusBar.visible": true,
5063
"workbench.editor.tabSizing": "fit",
5164
"workbench.sideBar.location": "left",
52-
// Debug
65+
// ? Debug - personal prefrences for debugging
5366
"debug.toolBarLocation": "floating",
5467
"debug.allowBreakpointsEverywhere": true,
55-
// Console
68+
// ? Console - self explanitory
5669
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\bash.exe", // C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe
57-
// Files
70+
// ? Files - exclude extensions/files and turn autosave on/off
5871
"files.autoSave": "off",
5972
"files.exclude": {
6073
"**/.git": false,
@@ -63,18 +76,18 @@
6376
"**/CVS": false,
6477
"**/.DS_Store": false
6578
},
66-
// Breadcrumbs
79+
// ? Breadcrumbs - the bar at the top with the current function path
6780
"breadcrumbs.enabled": true,
6881
"breadcrumbs.filePath": "last",
6982
"breadcrumbs.symbolPath": "on",
7083
"breadcrumbs.symbolSortOrder": "name",
71-
// Git
84+
// ? Git (version management)
7285
"git.enableSmartCommit": true,
7386
"git.ignoreLimitWarning": true,
74-
// ESlint
87+
// ? ESlint - linter to keep my code clean
7588
"eslint.enable": true,
7689
"eslint.packageManager": "yarn",
77-
// Languages
90+
// ? Languages - language-specific settings
7891
"[yaml]": {
7992
"editor.tabSize": 2,
8093
"editor.autoIndent": false,
@@ -84,6 +97,63 @@
8497
"editor.wordWrap": "on",
8598
"editor.quickSuggestions": false
8699
},
87-
// Live share
100+
// ? Live share - coding in or with friends
88101
"liveshare.featureSet": "insiders",
102+
// ? Better comments - Colorizes comments
103+
"better-comments.tags": [
104+
{
105+
"tag": "/",
106+
"color": "#008080",
107+
"strikethrough": false,
108+
"backgroundColor": "transparent"
109+
},
110+
{
111+
"tag": "+",
112+
"color": "#00ff00",
113+
"strikethrough": false,
114+
"backgroundColor": "transparent"
115+
},
116+
{
117+
"tag": ">",
118+
"color": "#FF00FF",
119+
"strikethrough": false,
120+
"backgroundColor": "transparent"
121+
},
122+
{
123+
"tag": "-",
124+
"color": "#ff0000",
125+
"strikethrough": false,
126+
"backgroundColor": "transparent"
127+
},
128+
{
129+
"tag": "!",
130+
"color": "#FF2D00",
131+
"strikethrough": false,
132+
"backgroundColor": "transparent"
133+
},
134+
{
135+
"tag": "?",
136+
"color": "#3498DB",
137+
"strikethrough": false,
138+
"backgroundColor": "transparent"
139+
},
140+
{
141+
"tag": "//",
142+
"color": "#474747",
143+
"strikethrough": true,
144+
"backgroundColor": "transparent"
145+
},
146+
{
147+
"tag": "todo",
148+
"color": "#FF8C00",
149+
"strikethrough": false,
150+
"backgroundColor": "transparent"
151+
},
152+
{
153+
"tag": "*",
154+
"color": "#98C379",
155+
"strikethrough": false,
156+
"backgroundColor": "transparent"
157+
}
158+
]
89159
}

.vscode/snippets.code-snippets

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
// Place your global snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
3-
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
4-
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
5-
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
6-
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
2+
// Place your global snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
3+
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
4+
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
5+
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
6+
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
77
// Placeholders with the same ids are connected.
88
// Example:
99
// "Print to console": {

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
The MIT License (MIT)
33

4-
Copyright (c) 2019-present Wessel "wesselgame" T <discord@go2it.eu>
4+
Copyright (c) 2019 Wessel "PassTheWessel" T <discord@go2it.eu>
55

66
Permission is hereby granted, free of charge, to any person obtaining a copy
77
of this software and associated documentation files (the "Software"), to deal

README.md

+43-2
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,46 @@ Deconstructed : 1547567141880
6060
```
6161

6262
### What is a snowflake?
63-
Snowflakes are strings that range from 14 to 19 characters long that can give every user it's unique idea. You can't get much data with just a snowflake, but you can get the creation date of the snowflake and identify every unique user with it.
64-
![Refrence Image](media/refrence.png "This is a refrence to what snowflakes are")
63+
Snowflakes are strings that range from 14 to 19 characters long that can give every user it's unique ID. You can't get much data with just a snowflake, but you can get the creation date of the snowflake and identify every unique user with it.
64+
```
65+
#--[ Example on how snowflakes work using Discord's Epoch ]--#
66+
18
67+
107130754189766656
68+
| to binary
69+
57 ↓ 23 18 13
70+
[1011111001001101011011010011101000][00000][000011][000000000000]
71+
Number of MS since Discord's Epoch internal internal incremented for
72+
(the first second of 2015) worker process every generated ID
73+
| to decimal ID ID on that process
74+
75+
12770981096
76+
| +1420070400000
77+
↓ Discord Epoch (unix timestamp in ms)
78+
1432841381096
79+
| Parse unix timestamp (ms)
80+
81+
2015-05-28T19:29:41.096Z UTC
82+
```
83+
84+
### What is a token?
85+
Tokens are almost always used to access an API, tokens are (almost) always secret and only available to be viewed by the creator of the token. Snowflakey makes tokens that exist out of 3 parts: the user's ID, the current time and a Hmac hash. Below is an example on how it works
86+
87+
```
88+
#--[ Example on how tokens work ]--#
89+
80 56 44
90+
[MTA3MTMwNzU0MTg5NzY2NjU2].[MTg1MzkyNzk].[efdZism4cPVwMynra4491_c_05Hi5WuCptgWqlW5bFbY0]
91+
The user's ID Current time Hmac hash (digest: Base64) that Consists
92+
|________ __________| out of TTF + version + part[0] + part[1]
93+
| From base64
94+
95+
[107130754189766656].[18539279]
96+
| Resolve | * 1000 to
97+
↓ the User ↓ convert it to ms
98+
Wesselgame#0498 18539279000
99+
| +1546300800000
100+
↓ add Epoch (the first second of 2019)
101+
1564840079000
102+
| Parse unix timestamp (ms)
103+
104+
2019-08-03T13:47:59.000Z UTC
105+
```

dist/lib/Master.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
const events_1 = require("events");
4+
class SnowflakeMaster extends events_1.EventEmitter {
5+
constructor() {
6+
super();
7+
this.setMaxListeners(1000);
8+
this.workers = [];
9+
}
10+
addWorkers(...workers) {
11+
for (const worker of workers) {
12+
this.workers.push(worker);
13+
}
14+
return this.refresh();
15+
}
16+
listWorkers() {
17+
return this.workers;
18+
}
19+
removeWorkers(...identities) {
20+
let found = 0;
21+
for (const identity of identities) {
22+
for (let i in this.workers) {
23+
const worker = this.workers[i];
24+
if (worker.options.name === identity || worker.options.workerId === identity) {
25+
found++;
26+
this.workers.splice(parseInt(i), 1);
27+
}
28+
}
29+
}
30+
return { removed: found };
31+
}
32+
refresh() {
33+
for (let worker of this.workers) {
34+
worker.on('newSnowflake', (...args) => this.emit('newSnowflake', ...args));
35+
worker.on('deconstructedFlake', (...args) => this.emit('deconstructedFlake', ...args));
36+
}
37+
}
38+
}
39+
exports.default = SnowflakeMaster;

dist/lib/Snowflake/Master.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
const events_1 = require("events");
4+
class SnowflakeMaster extends events_1.EventEmitter {
5+
constructor() {
6+
super();
7+
this.setMaxListeners(1000);
8+
this.workers = [];
9+
}
10+
addWorkers(...workers) {
11+
for (const worker of workers)
12+
this.workers.push(worker);
13+
return this.refresh();
14+
}
15+
listWorkers() {
16+
return this.workers;
17+
}
18+
removeWorkers(...identities) {
19+
let found = 0;
20+
for (const identity of identities) {
21+
for (let i in this.workers) {
22+
const worker = this.workers[i];
23+
if (worker.options.name === identity || worker.options.workerId === identity) {
24+
found++;
25+
this.workers.splice(parseInt(i), 1);
26+
}
27+
}
28+
}
29+
return { removed: found };
30+
}
31+
refresh() {
32+
for (let worker of this.workers) {
33+
worker.on('newSnowflake', (...args) => this.emit('newSnowflake', ...args));
34+
worker.on('deconstructedFlake', (...args) => this.emit('deconstructedFlake', ...args));
35+
}
36+
}
37+
}
38+
exports.default = SnowflakeMaster;

0 commit comments

Comments
 (0)