Add token generation

This commit is contained in:
Wessel Tip
2019-08-05 19:26:05 +02:00
parent 496cd5641c
commit 6f622cea94
44 changed files with 3574 additions and 124 deletions

View File

@@ -5,4 +5,4 @@ indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = false
insert_final_newline = true

View File

@@ -33,6 +33,7 @@
"templateStrings": true,
"superInFunctions": true,
"unicodeCodePointEscapes": true,
"experimentalObjectRestSpread": true,
"objectLiteralShorthandMethods": true,
"objectLiteralComputedProperties": true,
"objectLiteralDuplicateProperties": true,
@@ -42,7 +43,7 @@
"plugins": [],
"rules": {
"semi": "warn",
"indent": [ 0, 2 ],
"indent": [ "off", "error" ],
"strict": "off",
"eqeqeq": "error",
"no-var": "warn",
@@ -62,4 +63,4 @@
"_config": false,
"console": false
}
}
}

1
.gitignore vendored
View File

@@ -1,2 +1 @@
node_modules/
dist/

114
.vscode/settings.json vendored
View File

@@ -1,31 +1,43 @@
/*
General vscode settings for all my projects
Made by Wessel "wesselgame" T <discord@go2it.eu> (https://github.com/PassTheWessel)
/ General vscode settings for all my projects
/ Made by Wessel "wesselgame" T <discord@go2it.eu> (https://github.com/PassTheWessel)
Extensions: rainglow, eslint, tslint, material icon theme, gitlens, fish-vscode, Docker,
Popping and Locking theme, Sass, stylelint, SVG viewer, Trailing spaces, Auto renaming tags
? Extensions: rainglow, eslint, material icon theme, gitlens, fish-vscode, Docker, EditorConfig for VS Code
? Popping and Locking theme, Sass, stylelint, SVG viewer, Trailing spaces, Auto renaming tags, Better Comments,
? Regex previewer
Color themes: Banner (rainglow), Hyrule (rainglow), Azure (rainglow), Github (rainglow),
Heroku (rainglow), Popping and Locking
* Color themes: Banner (rainglow), Hyrule (rainglow), Azure (rainglow), Github (rainglow),
* Heroku (rainglow), Popping and Locking
* Comment legend:
/ Info
* Note
? Question
! Somenthing's wrong
> Changed
+ Added
- Removed
todo TODO
*/
{
// Window
// ? Window - the window options
"window.zoomLevel": 0,
// Editor
// ? Editor - the text editor config
"editor.fontSize": 13,
"editor.fontWeight": "200",
"editor.fontFamily": "'SFMono-Regular','Consolas','Liberation Mono','Menlo','Courier','monospace'",
"editor.fontFamily": "'SFMono-Regular','Consolas','Liberation Mono','Menlo','Courier','monospace','Operator Mono SSm Lig','OperatorMonoSSmLig-Book'",
"editor.lineHeight": 20,
"editor.fontLigatures": true,
"editor.cursorStyle": "line",
"editor.lineNumbers": "relative",
"editor.cursorWidth": 0,
"editor.fontLigatures": true,
"editor.cursorBlinking": "blink",
"editor.multiCursorModifier": "ctrlCmd",
"editor.minimap.enabled": true,
"editor.smoothScrolling": true,
"editor.multiCursorModifier": "ctrlCmd",
"editor.minimap.renderCharacters": true,
"editor.tabSize": 2,
"editor.autoIndent": false,
"editor.autoIndent": true,
"editor.insertSpaces": true,
"editor.tabCompletion": "on",
"editor.formatOnPaste": true,
@@ -43,18 +55,19 @@
"variables": "#C55F45",
"functions": "#C59F55"
},
//Workbench
// ? Workbench - the general working area
"workbench.iconTheme": "material-icon-theme",
"workbench.colorTheme": "Banner (rainglow)",
"workbench.colorTheme": "Darkside (rainglow)",
"workbench.editor.showTabs": true,
"workbench.statusBar.visible": true,
"workbench.editor.tabSizing": "fit",
"workbench.sideBar.location": "left",
// Debug
// ? Debug - personal prefrences for debugging
"debug.toolBarLocation": "floating",
"debug.allowBreakpointsEverywhere": true,
// Console
// ? Console - self explanitory
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\bash.exe", // C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe
// Files
// ? Files - exclude extensions/files and turn autosave on/off
"files.autoSave": "off",
"files.exclude": {
"**/.git": false,
@@ -63,18 +76,18 @@
"**/CVS": false,
"**/.DS_Store": false
},
// Breadcrumbs
// ? Breadcrumbs - the bar at the top with the current function path
"breadcrumbs.enabled": true,
"breadcrumbs.filePath": "last",
"breadcrumbs.symbolPath": "on",
"breadcrumbs.symbolSortOrder": "name",
// Git
// ? Git (version management)
"git.enableSmartCommit": true,
"git.ignoreLimitWarning": true,
// ESlint
// ? ESlint - linter to keep my code clean
"eslint.enable": true,
"eslint.packageManager": "yarn",
// Languages
// ? Languages - language-specific settings
"[yaml]": {
"editor.tabSize": 2,
"editor.autoIndent": false,
@@ -84,6 +97,63 @@
"editor.wordWrap": "on",
"editor.quickSuggestions": false
},
// Live share
// ? Live share - coding in or with friends
"liveshare.featureSet": "insiders",
// ? Better comments - Colorizes comments
"better-comments.tags": [
{
"tag": "/",
"color": "#008080",
"strikethrough": false,
"backgroundColor": "transparent"
},
{
"tag": "+",
"color": "#00ff00",
"strikethrough": false,
"backgroundColor": "transparent"
},
{
"tag": ">",
"color": "#FF00FF",
"strikethrough": false,
"backgroundColor": "transparent"
},
{
"tag": "-",
"color": "#ff0000",
"strikethrough": false,
"backgroundColor": "transparent"
},
{
"tag": "!",
"color": "#FF2D00",
"strikethrough": false,
"backgroundColor": "transparent"
},
{
"tag": "?",
"color": "#3498DB",
"strikethrough": false,
"backgroundColor": "transparent"
},
{
"tag": "//",
"color": "#474747",
"strikethrough": true,
"backgroundColor": "transparent"
},
{
"tag": "todo",
"color": "#FF8C00",
"strikethrough": false,
"backgroundColor": "transparent"
},
{
"tag": "*",
"color": "#98C379",
"strikethrough": false,
"backgroundColor": "transparent"
}
]
}

View File

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

View File

@@ -1,7 +1,7 @@
The MIT License (MIT)
Copyright (c) 2019-present Wessel "wesselgame" T <discord@go2it.eu>
Copyright (c) 2019 Wessel "PassTheWessel" T <discord@go2it.eu>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -60,5 +60,46 @@ Deconstructed : 1547567141880
```
### What is a snowflake?
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.
![Refrence Image](media/refrence.png "This is a refrence to what snowflakes are")
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.
```
#--[ Example on how snowflakes work using Discord's Epoch ]--#
18
107130754189766656
| to binary
57 ↓ 23 18 13
[1011111001001101011011010011101000][00000][000011][000000000000]
Number of MS since Discord's Epoch internal internal incremented for
(the first second of 2015) worker process every generated ID
| to decimal ID ID on that process
12770981096
| +1420070400000
↓ Discord Epoch (unix timestamp in ms)
1432841381096
| Parse unix timestamp (ms)
2015-05-28T19:29:41.096Z UTC
```
### What is a token?
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
```
#--[ Example on how tokens work ]--#
80 56 44
[MTA3MTMwNzU0MTg5NzY2NjU2].[MTg1MzkyNzk].[efdZism4cPVwMynra4491_c_05Hi5WuCptgWqlW5bFbY0]
The user's ID Current time Hmac hash (digest: Base64) that Consists
|________ __________| out of TTF + version + part[0] + part[1]
| From base64
[107130754189766656].[18539279]
| Resolve | * 1000 to
↓ the User ↓ convert it to ms
Wesselgame#0498 18539279000
| +1546300800000
↓ add Epoch (the first second of 2019)
1564840079000
| Parse unix timestamp (ms)
2019-08-03T13:47:59.000Z UTC
```

39
dist/lib/Master.js vendored Normal file
View File

@@ -0,0 +1,39 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const events_1 = require("events");
class SnowflakeMaster extends events_1.EventEmitter {
constructor() {
super();
this.setMaxListeners(1000);
this.workers = [];
}
addWorkers(...workers) {
for (const worker of workers) {
this.workers.push(worker);
}
return this.refresh();
}
listWorkers() {
return this.workers;
}
removeWorkers(...identities) {
let found = 0;
for (const identity of identities) {
for (let i in this.workers) {
const worker = this.workers[i];
if (worker.options.name === identity || worker.options.workerId === identity) {
found++;
this.workers.splice(parseInt(i), 1);
}
}
}
return { removed: found };
}
refresh() {
for (let worker of this.workers) {
worker.on('newSnowflake', (...args) => this.emit('newSnowflake', ...args));
worker.on('deconstructedFlake', (...args) => this.emit('deconstructedFlake', ...args));
}
}
}
exports.default = SnowflakeMaster;

38
dist/lib/Snowflake/Master.js vendored Normal file
View File

@@ -0,0 +1,38 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const events_1 = require("events");
class SnowflakeMaster extends events_1.EventEmitter {
constructor() {
super();
this.setMaxListeners(1000);
this.workers = [];
}
addWorkers(...workers) {
for (const worker of workers)
this.workers.push(worker);
return this.refresh();
}
listWorkers() {
return this.workers;
}
removeWorkers(...identities) {
let found = 0;
for (const identity of identities) {
for (let i in this.workers) {
const worker = this.workers[i];
if (worker.options.name === identity || worker.options.workerId === identity) {
found++;
this.workers.splice(parseInt(i), 1);
}
}
}
return { removed: found };
}
refresh() {
for (let worker of this.workers) {
worker.on('newSnowflake', (...args) => this.emit('newSnowflake', ...args));
worker.on('deconstructedFlake', (...args) => this.emit('deconstructedFlake', ...args));
}
}
}
exports.default = SnowflakeMaster;

121
dist/lib/Snowflake/Worker.js vendored Normal file
View File

@@ -0,0 +1,121 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const bigInt_1 = __importDefault(require("./bigInt"));
const events_1 = require("events");
const util_1 = require("./util");
class SnowflakeWorker extends events_1.EventEmitter {
constructor(options) {
super();
this.setMaxListeners(100);
this.options = {
name: undefined,
async: false,
stringify: true,
workerId: 0,
processId: 0,
workerBits: 5,
processBits: 5,
incrementBits: 12,
epoch: null,
...options
};
this._mutable = {
locks: [],
locked: false,
increment: bigInt_1.default.zero.subtract(1),
lastTimestamp: Date.now()
};
if (this.options.incrementBits + this.options.processBits + this.options.workerBits !== 22)
throw new Error('incrementBits, processBits, and workerBits must add up to 22.');
this.options.workerId = this.options.workerId % (2 ** this.options.workerBits);
this.options.processId = this.options.processId % (2 ** this.options.processBits);
if (isNaN(this.options.workerId))
this.options.workerId = 0;
if (isNaN(this.options.processId))
this.options.processId = 0;
this._maxIncrement = 2 ** this.options.incrementBits;
this.workerId = bigInt_1.default(this.options.workerId).shiftLeft(this.options.incrementBits + this.options.processBits);
this.processId = bigInt_1.default(this.options.processId).shiftLeft(this.options.incrementBits);
Object.freeze(this.options);
}
get increment() {
return this._mutable.increment = this._mutable.increment.next().mod(this._maxIncrement);
}
generate() {
if (this.options.async)
return this._generateAsync();
else
return this._generate();
}
_generate(date = Date.now(), increment = this.increment) {
let flake = bigInt_1.default(date).minus(this.options.epoch).shiftLeft(22)
.add(this.workerId)
.add(this.processId)
.add(increment);
this.emit('newSnowflake', {
worker: this,
method: 'sync',
snowflake: flake,
});
if (this.options.stringify)
flake = flake.toString();
return flake;
}
_lock() {
if (this._mutable.locked)
return new Promise(res => this._mutable.locks.push(res));
else
this._mutable.locked = true;
}
_unlock() {
if (this._mutable.locks.length > 0)
this._mutable.locks.shift()();
else
this._mutable.locked = false;
}
async _generateAsync() {
let lock = this._lock();
if (lock)
await lock;
let now = Date.now();
if (this._mutable.lastTimestamp !== now) {
this._mutable.increment = bigInt_1.default.zero;
this._mutable.lastTimestamp = now;
}
else {
this._mutable.increment = this._mutable.increment.next();
if (this._mutable.increment.greaterOrEquals(this._maxIncrement)) {
await util_1.sleep(2 / 1000);
this._mutable.increment = bigInt_1.default.zero;
now = this._mutable.lastTimestamp = Date.now();
}
}
let flake = this._generate(now, this._mutable.increment);
this._unlock();
this.emit('newSnowflake', {
worker: this,
method: 'sync',
snowflake: flake,
});
return flake;
}
deconstruct(snowflake, epoch = this.options.epoch) {
let flake = bigInt_1.default(snowflake);
let timestamp = flake.shiftRight(22).add(epoch);
let wBitShift = this.options.incrementBits + this.options.processBits;
let workerId = flake.and(bigInt_1.default(util_1.getBits(this.options.workerBits)).shiftLeft(wBitShift)).shiftRight(wBitShift);
let processId = flake.and(bigInt_1.default(util_1.getBits(this.options.processBits)).shiftLeft(this.options.incrementBits)).shiftRight(this.options.incrementBits);
let increment = flake.and(util_1.getBits(this.options.incrementBits));
this.emit('deconstructedFlake', {
worker: this,
method: 'sync',
timestamp, workerId, processId, increment
});
return { timestamp, workerId, processId, increment };
}
}
exports.default = SnowflakeWorker;
;

747
dist/lib/Snowflake/bigInt.js vendored Normal file
View File

@@ -0,0 +1,747 @@
var bigInt = function (undefined) {
"use strict";
var BASE = 1e7, LOG_BASE = 7, MAX_INT = 9007199254740992, MAX_INT_ARR = smallToArray(MAX_INT), DEFAULT_ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyz";
var supportsNativeBigInt = typeof BigInt === "function";
function Integer(v, radix, alphabet, caseSensitive) { if (typeof v === "undefined")
return Integer[0]; if (typeof radix !== "undefined")
return +radix === 10 && !alphabet ? parseValue(v) : parseBase(v, radix, alphabet, caseSensitive); return parseValue(v); }
function BigInteger(value, sign) { this.value = value; this.sign = sign; this.isSmall = false; }
BigInteger.prototype = Object.create(Integer.prototype);
function SmallInteger(value) { this.value = value; this.sign = value < 0; this.isSmall = true; }
SmallInteger.prototype = Object.create(Integer.prototype);
function NativeBigInt(value) { this.value = value; }
NativeBigInt.prototype = Object.create(Integer.prototype);
function isPrecise(n) { return -MAX_INT < n && n < MAX_INT; }
function smallToArray(n) { if (n < 1e7)
return [n]; if (n < 1e14)
return [n % 1e7, Math.floor(n / 1e7)]; return [n % 1e7, Math.floor(n / 1e7) % 1e7, Math.floor(n / 1e14)]; }
function arrayToSmall(arr) { trim(arr); var length = arr.length; if (length < 4 && compareAbs(arr, MAX_INT_ARR) < 0) {
switch (length) {
case 0: return 0;
case 1: return arr[0];
case 2: return arr[0] + arr[1] * BASE;
default: return arr[0] + (arr[1] + arr[2] * BASE) * BASE;
}
} return arr; }
function trim(v) { var i = v.length; while (v[--i] === 0)
; v.length = i + 1; }
function createArray(length) { var x = new Array(length); var i = -1; while (++i < length) {
x[i] = 0;
} return x; }
function truncate(n) { if (n > 0)
return Math.floor(n); return Math.ceil(n); }
function add(a, b) { var l_a = a.length, l_b = b.length, r = new Array(l_a), carry = 0, base = BASE, sum, i; for (i = 0; i < l_b; i++) {
sum = a[i] + b[i] + carry;
carry = sum >= base ? 1 : 0;
r[i] = sum - carry * base;
} while (i < l_a) {
sum = a[i] + carry;
carry = sum === base ? 1 : 0;
r[i++] = sum - carry * base;
} if (carry > 0)
r.push(carry); return r; }
function addAny(a, b) { if (a.length >= b.length)
return add(a, b); return add(b, a); }
function addSmall(a, carry) { var l = a.length, r = new Array(l), base = BASE, sum, i; for (i = 0; i < l; i++) {
sum = a[i] - base + carry;
carry = Math.floor(sum / base);
r[i] = sum - carry * base;
carry += 1;
} while (carry > 0) {
r[i++] = carry % base;
carry = Math.floor(carry / base);
} return r; }
BigInteger.prototype.add = function (v) { var n = parseValue(v); if (this.sign !== n.sign) {
return this.subtract(n.negate());
} var a = this.value, b = n.value; if (n.isSmall) {
return new BigInteger(addSmall(a, Math.abs(b)), this.sign);
} return new BigInteger(addAny(a, b), this.sign); };
BigInteger.prototype.plus = BigInteger.prototype.add;
SmallInteger.prototype.add = function (v) { var n = parseValue(v); var a = this.value; if (a < 0 !== n.sign) {
return this.subtract(n.negate());
} var b = n.value; if (n.isSmall) {
if (isPrecise(a + b))
return new SmallInteger(a + b);
b = smallToArray(Math.abs(b));
} return new BigInteger(addSmall(b, Math.abs(a)), a < 0); };
SmallInteger.prototype.plus = SmallInteger.prototype.add;
NativeBigInt.prototype.add = function (v) { return new NativeBigInt(this.value + parseValue(v).value); };
NativeBigInt.prototype.plus = NativeBigInt.prototype.add;
function subtract(a, b) { var a_l = a.length, b_l = b.length, r = new Array(a_l), borrow = 0, base = BASE, i, difference; for (i = 0; i < b_l; i++) {
difference = a[i] - borrow - b[i];
if (difference < 0) {
difference += base;
borrow = 1;
}
else
borrow = 0;
r[i] = difference;
} for (i = b_l; i < a_l; i++) {
difference = a[i] - borrow;
if (difference < 0)
difference += base;
else {
r[i++] = difference;
break;
}
r[i] = difference;
} for (; i < a_l; i++) {
r[i] = a[i];
} trim(r); return r; }
function subtractAny(a, b, sign) { var value; if (compareAbs(a, b) >= 0) {
value = subtract(a, b);
}
else {
value = subtract(b, a);
sign = !sign;
} value = arrayToSmall(value); if (typeof value === "number") {
if (sign)
value = -value;
return new SmallInteger(value);
} return new BigInteger(value, sign); }
function subtractSmall(a, b, sign) { var l = a.length, r = new Array(l), carry = -b, base = BASE, i, difference; for (i = 0; i < l; i++) {
difference = a[i] + carry;
carry = Math.floor(difference / base);
difference %= base;
r[i] = difference < 0 ? difference + base : difference;
} r = arrayToSmall(r); if (typeof r === "number") {
if (sign)
r = -r;
return new SmallInteger(r);
} return new BigInteger(r, sign); }
BigInteger.prototype.subtract = function (v) { var n = parseValue(v); if (this.sign !== n.sign) {
return this.add(n.negate());
} var a = this.value, b = n.value; if (n.isSmall)
return subtractSmall(a, Math.abs(b), this.sign); return subtractAny(a, b, this.sign); };
BigInteger.prototype.minus = BigInteger.prototype.subtract;
SmallInteger.prototype.subtract = function (v) { var n = parseValue(v); var a = this.value; if (a < 0 !== n.sign) {
return this.add(n.negate());
} var b = n.value; if (n.isSmall) {
return new SmallInteger(a - b);
} return subtractSmall(b, Math.abs(a), a >= 0); };
SmallInteger.prototype.minus = SmallInteger.prototype.subtract;
NativeBigInt.prototype.subtract = function (v) { return new NativeBigInt(this.value - parseValue(v).value); };
NativeBigInt.prototype.minus = NativeBigInt.prototype.subtract;
BigInteger.prototype.negate = function () { return new BigInteger(this.value, !this.sign); };
SmallInteger.prototype.negate = function () { var sign = this.sign; var small = new SmallInteger(-this.value); small.sign = !sign; return small; };
NativeBigInt.prototype.negate = function () { return new NativeBigInt(-this.value); };
BigInteger.prototype.abs = function () { return new BigInteger(this.value, false); };
SmallInteger.prototype.abs = function () { return new SmallInteger(Math.abs(this.value)); };
NativeBigInt.prototype.abs = function () { return new NativeBigInt(this.value >= 0 ? this.value : -this.value); };
function multiplyLong(a, b) { var a_l = a.length, b_l = b.length, l = a_l + b_l, r = createArray(l), base = BASE, product, carry, i, a_i, b_j; for (i = 0; i < a_l; ++i) {
a_i = a[i];
for (var j = 0; j < b_l; ++j) {
b_j = b[j];
product = a_i * b_j + r[i + j];
carry = Math.floor(product / base);
r[i + j] = product - carry * base;
r[i + j + 1] += carry;
}
} trim(r); return r; }
function multiplySmall(a, b) { var l = a.length, r = new Array(l), base = BASE, carry = 0, product, i; for (i = 0; i < l; i++) {
product = a[i] * b + carry;
carry = Math.floor(product / base);
r[i] = product - carry * base;
} while (carry > 0) {
r[i++] = carry % base;
carry = Math.floor(carry / base);
} return r; }
function shiftLeft(x, n) { var r = []; while (n-- > 0)
r.push(0); return r.concat(x); }
function multiplyKaratsuba(x, y) { var n = Math.max(x.length, y.length); if (n <= 30)
return multiplyLong(x, y); n = Math.ceil(n / 2); var b = x.slice(n), a = x.slice(0, n), d = y.slice(n), c = y.slice(0, n); var ac = multiplyKaratsuba(a, c), bd = multiplyKaratsuba(b, d), abcd = multiplyKaratsuba(addAny(a, b), addAny(c, d)); var product = addAny(addAny(ac, shiftLeft(subtract(subtract(abcd, ac), bd), n)), shiftLeft(bd, 2 * n)); trim(product); return product; }
function useKaratsuba(l1, l2) { return -.012 * l1 - .012 * l2 + 15e-6 * l1 * l2 > 0; }
BigInteger.prototype.multiply = function (v) { var n = parseValue(v), a = this.value, b = n.value, sign = this.sign !== n.sign, abs; if (n.isSmall) {
if (b === 0)
return Integer[0];
if (b === 1)
return this;
if (b === -1)
return this.negate();
abs = Math.abs(b);
if (abs < BASE) {
return new BigInteger(multiplySmall(a, abs), sign);
}
b = smallToArray(abs);
} if (useKaratsuba(a.length, b.length))
return new BigInteger(multiplyKaratsuba(a, b), sign); return new BigInteger(multiplyLong(a, b), sign); };
BigInteger.prototype.times = BigInteger.prototype.multiply;
function multiplySmallAndArray(a, b, sign) { if (a < BASE) {
return new BigInteger(multiplySmall(b, a), sign);
} return new BigInteger(multiplyLong(b, smallToArray(a)), sign); }
SmallInteger.prototype._multiplyBySmall = function (a) { if (isPrecise(a.value * this.value)) {
return new SmallInteger(a.value * this.value);
} return multiplySmallAndArray(Math.abs(a.value), smallToArray(Math.abs(this.value)), this.sign !== a.sign); };
BigInteger.prototype._multiplyBySmall = function (a) { if (a.value === 0)
return Integer[0]; if (a.value === 1)
return this; if (a.value === -1)
return this.negate(); return multiplySmallAndArray(Math.abs(a.value), this.value, this.sign !== a.sign); };
SmallInteger.prototype.multiply = function (v) { return parseValue(v)._multiplyBySmall(this); };
SmallInteger.prototype.times = SmallInteger.prototype.multiply;
NativeBigInt.prototype.multiply = function (v) { return new NativeBigInt(this.value * parseValue(v).value); };
NativeBigInt.prototype.times = NativeBigInt.prototype.multiply;
function square(a) { var l = a.length, r = createArray(l + l), base = BASE, product, carry, i, a_i, a_j; for (i = 0; i < l; i++) {
a_i = a[i];
carry = 0 - a_i * a_i;
for (var j = i; j < l; j++) {
a_j = a[j];
product = 2 * (a_i * a_j) + r[i + j] + carry;
carry = Math.floor(product / base);
r[i + j] = product - carry * base;
}
r[i + l] = carry;
} trim(r); return r; }
BigInteger.prototype.square = function () { return new BigInteger(square(this.value), false); };
SmallInteger.prototype.square = function () { var value = this.value * this.value; if (isPrecise(value))
return new SmallInteger(value); return new BigInteger(square(smallToArray(Math.abs(this.value))), false); };
NativeBigInt.prototype.square = function (v) { return new NativeBigInt(this.value * this.value); };
function divMod1(a, b) { var a_l = a.length, b_l = b.length, base = BASE, result = createArray(b.length), divisorMostSignificantDigit = b[b_l - 1], lambda = Math.ceil(base / (2 * divisorMostSignificantDigit)), remainder = multiplySmall(a, lambda), divisor = multiplySmall(b, lambda), quotientDigit, shift, carry, borrow, i, l, q; if (remainder.length <= a_l)
remainder.push(0); divisor.push(0); divisorMostSignificantDigit = divisor[b_l - 1]; for (shift = a_l - b_l; shift >= 0; shift--) {
quotientDigit = base - 1;
if (remainder[shift + b_l] !== divisorMostSignificantDigit) {
quotientDigit = Math.floor((remainder[shift + b_l] * base + remainder[shift + b_l - 1]) / divisorMostSignificantDigit);
}
carry = 0;
borrow = 0;
l = divisor.length;
for (i = 0; i < l; i++) {
carry += quotientDigit * divisor[i];
q = Math.floor(carry / base);
borrow += remainder[shift + i] - (carry - q * base);
carry = q;
if (borrow < 0) {
remainder[shift + i] = borrow + base;
borrow = -1;
}
else {
remainder[shift + i] = borrow;
borrow = 0;
}
}
while (borrow !== 0) {
quotientDigit -= 1;
carry = 0;
for (i = 0; i < l; i++) {
carry += remainder[shift + i] - base + divisor[i];
if (carry < 0) {
remainder[shift + i] = carry + base;
carry = 0;
}
else {
remainder[shift + i] = carry;
carry = 1;
}
}
borrow += carry;
}
result[shift] = quotientDigit;
} remainder = divModSmall(remainder, lambda)[0]; return [arrayToSmall(result), arrayToSmall(remainder)]; }
function divMod2(a, b) { var a_l = a.length, b_l = b.length, result = [], part = [], base = BASE, guess, xlen, highx, highy, check; while (a_l) {
part.unshift(a[--a_l]);
trim(part);
if (compareAbs(part, b) < 0) {
result.push(0);
continue;
}
xlen = part.length;
highx = part[xlen - 1] * base + part[xlen - 2];
highy = b[b_l - 1] * base + b[b_l - 2];
if (xlen > b_l) {
highx = (highx + 1) * base;
}
guess = Math.ceil(highx / highy);
do {
check = multiplySmall(b, guess);
if (compareAbs(check, part) <= 0)
break;
guess--;
} while (guess);
result.push(guess);
part = subtract(part, check);
} result.reverse(); return [arrayToSmall(result), arrayToSmall(part)]; }
function divModSmall(value, lambda) { var length = value.length, quotient = createArray(length), base = BASE, i, q, remainder, divisor; remainder = 0; for (i = length - 1; i >= 0; --i) {
divisor = remainder * base + value[i];
q = truncate(divisor / lambda);
remainder = divisor - q * lambda;
quotient[i] = q | 0;
} return [quotient, remainder | 0]; }
function divModAny(self, v) { var value, n = parseValue(v); if (supportsNativeBigInt) {
return [new NativeBigInt(self.value / n.value), new NativeBigInt(self.value % n.value)];
} var a = self.value, b = n.value; var quotient; if (b === 0)
throw new Error("Cannot divide by zero"); if (self.isSmall) {
if (n.isSmall) {
return [new SmallInteger(truncate(a / b)), new SmallInteger(a % b)];
}
return [Integer[0], self];
} if (n.isSmall) {
if (b === 1)
return [self, Integer[0]];
if (b == -1)
return [self.negate(), Integer[0]];
var abs = Math.abs(b);
if (abs < BASE) {
value = divModSmall(a, abs);
quotient = arrayToSmall(value[0]);
var remainder = value[1];
if (self.sign)
remainder = -remainder;
if (typeof quotient === "number") {
if (self.sign !== n.sign)
quotient = -quotient;
return [new SmallInteger(quotient), new SmallInteger(remainder)];
}
return [new BigInteger(quotient, self.sign !== n.sign), new SmallInteger(remainder)];
}
b = smallToArray(abs);
} var comparison = compareAbs(a, b); if (comparison === -1)
return [Integer[0], self]; if (comparison === 0)
return [Integer[self.sign === n.sign ? 1 : -1], Integer[0]]; if (a.length + b.length <= 200)
value = divMod1(a, b);
else
value = divMod2(a, b); quotient = value[0]; var qSign = self.sign !== n.sign, mod = value[1], mSign = self.sign; if (typeof quotient === "number") {
if (qSign)
quotient = -quotient;
quotient = new SmallInteger(quotient);
}
else
quotient = new BigInteger(quotient, qSign); if (typeof mod === "number") {
if (mSign)
mod = -mod;
mod = new SmallInteger(mod);
}
else
mod = new BigInteger(mod, mSign); return [quotient, mod]; }
BigInteger.prototype.divmod = function (v) { var result = divModAny(this, v); return { quotient: result[0], remainder: result[1] }; };
NativeBigInt.prototype.divmod = SmallInteger.prototype.divmod = BigInteger.prototype.divmod;
BigInteger.prototype.divide = function (v) { return divModAny(this, v)[0]; };
NativeBigInt.prototype.over = NativeBigInt.prototype.divide = SmallInteger.prototype.over = SmallInteger.prototype.divide = BigInteger.prototype.over = BigInteger.prototype.divide;
BigInteger.prototype.mod = function (v) { return divModAny(this, v)[1]; };
NativeBigInt.prototype.mod = NativeBigInt.prototype.remainder = SmallInteger.prototype.remainder = SmallInteger.prototype.mod = BigInteger.prototype.remainder = BigInteger.prototype.mod;
BigInteger.prototype.pow = function (v) { var n = parseValue(v), a = this.value, b = n.value, value, x, y; if (b === 0)
return Integer[1]; if (a === 0)
return Integer[0]; if (a === 1)
return Integer[1]; if (a === -1)
return n.isEven() ? Integer[1] : Integer[-1]; if (n.sign) {
return Integer[0];
} if (!n.isSmall)
throw new Error("The exponent " + n.toString() + " is too large."); if (this.isSmall) {
if (isPrecise(value = Math.pow(a, b)))
return new SmallInteger(truncate(value));
} x = this; y = Integer[1]; while (true) {
if (b & 1 === 1) {
y = y.times(x);
--b;
}
if (b === 0)
break;
b /= 2;
x = x.square();
} return y; };
SmallInteger.prototype.pow = BigInteger.prototype.pow;
var pow;
if (supportsNativeBigInt) {
pow = eval("(a,b)=>a**b");
}
NativeBigInt.prototype.pow = function (v) { var n = parseValue(v); var a = this.value, b = n.value; if (b === BigInt(0))
return Integer[1]; if (a === BigInt(0))
return Integer[0]; if (a === BigInt(1))
return Integer[1]; if (a === BigInt(-1))
return n.isEven() ? Integer[1] : Integer[-1]; if (n.isNegative())
return new NativeBigInt(BigInt(0)); return new NativeBigInt(pow(a, b)); };
BigInteger.prototype.modPow = function (exp, mod) { exp = parseValue(exp); mod = parseValue(mod); if (mod.isZero())
throw new Error("Cannot take modPow with modulus 0"); var r = Integer[1], base = this.mod(mod); while (exp.isPositive()) {
if (base.isZero())
return Integer[0];
if (exp.isOdd())
r = r.multiply(base).mod(mod);
exp = exp.divide(2);
base = base.square().mod(mod);
} return r; };
NativeBigInt.prototype.modPow = SmallInteger.prototype.modPow = BigInteger.prototype.modPow;
function compareAbs(a, b) { if (a.length !== b.length) {
return a.length > b.length ? 1 : -1;
} for (var i = a.length - 1; i >= 0; i--) {
if (a[i] !== b[i])
return a[i] > b[i] ? 1 : -1;
} return 0; }
BigInteger.prototype.compareAbs = function (v) { var n = parseValue(v), a = this.value, b = n.value; if (n.isSmall)
return 1; return compareAbs(a, b); };
SmallInteger.prototype.compareAbs = function (v) { var n = parseValue(v), a = Math.abs(this.value), b = n.value; if (n.isSmall) {
b = Math.abs(b);
return a === b ? 0 : a > b ? 1 : -1;
} return -1; };
NativeBigInt.prototype.compareAbs = function (v) { var a = this.value; var b = parseValue(v).value; a = a >= 0 ? a : -a; b = b >= 0 ? b : -b; return a === b ? 0 : a > b ? 1 : -1; };
BigInteger.prototype.compare = function (v) { if (v === Infinity) {
return -1;
} if (v === -Infinity) {
return 1;
} var n = parseValue(v), a = this.value, b = n.value; if (this.sign !== n.sign) {
return n.sign ? 1 : -1;
} if (n.isSmall) {
return this.sign ? -1 : 1;
} return compareAbs(a, b) * (this.sign ? -1 : 1); };
BigInteger.prototype.compareTo = BigInteger.prototype.compare;
SmallInteger.prototype.compare = function (v) { if (v === Infinity) {
return -1;
} if (v === -Infinity) {
return 1;
} var n = parseValue(v), a = this.value, b = n.value; if (n.isSmall) {
return a == b ? 0 : a > b ? 1 : -1;
} if (a < 0 !== n.sign) {
return a < 0 ? -1 : 1;
} return a < 0 ? 1 : -1; };
SmallInteger.prototype.compareTo = SmallInteger.prototype.compare;
NativeBigInt.prototype.compare = function (v) { if (v === Infinity) {
return -1;
} if (v === -Infinity) {
return 1;
} var a = this.value; var b = parseValue(v).value; return a === b ? 0 : a > b ? 1 : -1; };
NativeBigInt.prototype.compareTo = NativeBigInt.prototype.compare;
BigInteger.prototype.equals = function (v) { return this.compare(v) === 0; };
NativeBigInt.prototype.eq = NativeBigInt.prototype.equals = SmallInteger.prototype.eq = SmallInteger.prototype.equals = BigInteger.prototype.eq = BigInteger.prototype.equals;
BigInteger.prototype.notEquals = function (v) { return this.compare(v) !== 0; };
NativeBigInt.prototype.neq = NativeBigInt.prototype.notEquals = SmallInteger.prototype.neq = SmallInteger.prototype.notEquals = BigInteger.prototype.neq = BigInteger.prototype.notEquals;
BigInteger.prototype.greater = function (v) { return this.compare(v) > 0; };
NativeBigInt.prototype.gt = NativeBigInt.prototype.greater = SmallInteger.prototype.gt = SmallInteger.prototype.greater = BigInteger.prototype.gt = BigInteger.prototype.greater;
BigInteger.prototype.lesser = function (v) { return this.compare(v) < 0; };
NativeBigInt.prototype.lt = NativeBigInt.prototype.lesser = SmallInteger.prototype.lt = SmallInteger.prototype.lesser = BigInteger.prototype.lt = BigInteger.prototype.lesser;
BigInteger.prototype.greaterOrEquals = function (v) { return this.compare(v) >= 0; };
NativeBigInt.prototype.geq = NativeBigInt.prototype.greaterOrEquals = SmallInteger.prototype.geq = SmallInteger.prototype.greaterOrEquals = BigInteger.prototype.geq = BigInteger.prototype.greaterOrEquals;
BigInteger.prototype.lesserOrEquals = function (v) { return this.compare(v) <= 0; };
NativeBigInt.prototype.leq = NativeBigInt.prototype.lesserOrEquals = SmallInteger.prototype.leq = SmallInteger.prototype.lesserOrEquals = BigInteger.prototype.leq = BigInteger.prototype.lesserOrEquals;
BigInteger.prototype.isEven = function () { return (this.value[0] & 1) === 0; };
SmallInteger.prototype.isEven = function () { return (this.value & 1) === 0; };
NativeBigInt.prototype.isEven = function () { return (this.value & BigInt(1)) === BigInt(0); };
BigInteger.prototype.isOdd = function () { return (this.value[0] & 1) === 1; };
SmallInteger.prototype.isOdd = function () { return (this.value & 1) === 1; };
NativeBigInt.prototype.isOdd = function () { return (this.value & BigInt(1)) === BigInt(1); };
BigInteger.prototype.isPositive = function () { return !this.sign; };
SmallInteger.prototype.isPositive = function () { return this.value > 0; };
NativeBigInt.prototype.isPositive = SmallInteger.prototype.isPositive;
BigInteger.prototype.isNegative = function () { return this.sign; };
SmallInteger.prototype.isNegative = function () { return this.value < 0; };
NativeBigInt.prototype.isNegative = SmallInteger.prototype.isNegative;
BigInteger.prototype.isUnit = function () { return false; };
SmallInteger.prototype.isUnit = function () { return Math.abs(this.value) === 1; };
NativeBigInt.prototype.isUnit = function () { return this.abs().value === BigInt(1); };
BigInteger.prototype.isZero = function () { return false; };
SmallInteger.prototype.isZero = function () { return this.value === 0; };
NativeBigInt.prototype.isZero = function () { return this.value === BigInt(0); };
BigInteger.prototype.isDivisibleBy = function (v) { var n = parseValue(v); if (n.isZero())
return false; if (n.isUnit())
return true; if (n.compareAbs(2) === 0)
return this.isEven(); return this.mod(n).isZero(); };
NativeBigInt.prototype.isDivisibleBy = SmallInteger.prototype.isDivisibleBy = BigInteger.prototype.isDivisibleBy;
function isBasicPrime(v) { var n = v.abs(); if (n.isUnit())
return false; if (n.equals(2) || n.equals(3) || n.equals(5))
return true; if (n.isEven() || n.isDivisibleBy(3) || n.isDivisibleBy(5))
return false; if (n.lesser(49))
return true; }
function millerRabinTest(n, a) { var nPrev = n.prev(), b = nPrev, r = 0, d, t, i, x; while (b.isEven())
b = b.divide(2), r++; next: for (i = 0; i < a.length; i++) {
if (n.lesser(a[i]))
continue;
x = bigInt(a[i]).modPow(b, n);
if (x.isUnit() || x.equals(nPrev))
continue;
for (d = r - 1; d != 0; d--) {
x = x.square().mod(n);
if (x.isUnit())
return false;
if (x.equals(nPrev))
continue next;
}
return false;
} return true; }
BigInteger.prototype.isPrime = function (strict) { var isPrime = isBasicPrime(this); if (isPrime !== undefined)
return isPrime; var n = this.abs(); var bits = n.bitLength(); if (bits <= 64)
return millerRabinTest(n, [2, 325, 9375, 28178, 450775, 9780504, 1795265022]); var logN = Math.log(2) * bits.toJSNumber(); var t = Math.ceil(strict === true ? 2 * Math.pow(logN, 2) : logN); for (var a = [], i = 0; i < t; i++) {
a.push(bigInt(i + 2));
} return millerRabinTest(n, a); };
NativeBigInt.prototype.isPrime = SmallInteger.prototype.isPrime = BigInteger.prototype.isPrime;
BigInteger.prototype.isProbablePrime = function (iterations) { var isPrime = isBasicPrime(this); if (isPrime !== undefined)
return isPrime; var n = this.abs(); var t = iterations === undefined ? 5 : iterations; for (var a = [], i = 0; i < t; i++) {
a.push(bigInt.randBetween(2, n.minus(2)));
} return millerRabinTest(n, a); };
NativeBigInt.prototype.isProbablePrime = SmallInteger.prototype.isProbablePrime = BigInteger.prototype.isProbablePrime;
BigInteger.prototype.modInv = function (n) { var t = bigInt.zero, newT = bigInt.one, r = parseValue(n), newR = this.abs(), q, lastT, lastR; while (!newR.isZero()) {
q = r.divide(newR);
lastT = t;
lastR = r;
t = newT;
r = newR;
newT = lastT.subtract(q.multiply(newT));
newR = lastR.subtract(q.multiply(newR));
} if (!r.isUnit())
throw new Error(this.toString() + " and " + n.toString() + " are not co-prime"); if (t.compare(0) === -1) {
t = t.add(n);
} if (this.isNegative()) {
return t.negate();
} return t; };
NativeBigInt.prototype.modInv = SmallInteger.prototype.modInv = BigInteger.prototype.modInv;
BigInteger.prototype.next = function () { var value = this.value; if (this.sign) {
return subtractSmall(value, 1, this.sign);
} return new BigInteger(addSmall(value, 1), this.sign); };
SmallInteger.prototype.next = function () { var value = this.value; if (value + 1 < MAX_INT)
return new SmallInteger(value + 1); return new BigInteger(MAX_INT_ARR, false); };
NativeBigInt.prototype.next = function () { return new NativeBigInt(this.value + BigInt(1)); };
BigInteger.prototype.prev = function () { var value = this.value; if (this.sign) {
return new BigInteger(addSmall(value, 1), true);
} return subtractSmall(value, 1, this.sign); };
SmallInteger.prototype.prev = function () { var value = this.value; if (value - 1 > -MAX_INT)
return new SmallInteger(value - 1); return new BigInteger(MAX_INT_ARR, true); };
NativeBigInt.prototype.prev = function () { return new NativeBigInt(this.value - BigInt(1)); };
var powersOfTwo = [1];
while (2 * powersOfTwo[powersOfTwo.length - 1] <= BASE)
powersOfTwo.push(2 * powersOfTwo[powersOfTwo.length - 1]);
var powers2Length = powersOfTwo.length, highestPower2 = powersOfTwo[powers2Length - 1];
function shift_isSmall(n) { return Math.abs(n) <= BASE; }
BigInteger.prototype.shiftLeft = function (v) { var n = parseValue(v).toJSNumber(); if (!shift_isSmall(n)) {
throw new Error(String(n) + " is too large for shifting.");
} if (n < 0)
return this.shiftRight(-n); var result = this; if (result.isZero())
return result; while (n >= powers2Length) {
result = result.multiply(highestPower2);
n -= powers2Length - 1;
} return result.multiply(powersOfTwo[n]); };
NativeBigInt.prototype.shiftLeft = SmallInteger.prototype.shiftLeft = BigInteger.prototype.shiftLeft;
BigInteger.prototype.shiftRight = function (v) { var remQuo; var n = parseValue(v).toJSNumber(); if (!shift_isSmall(n)) {
throw new Error(String(n) + " is too large for shifting.");
} if (n < 0)
return this.shiftLeft(-n); var result = this; while (n >= powers2Length) {
if (result.isZero() || result.isNegative() && result.isUnit())
return result;
remQuo = divModAny(result, highestPower2);
result = remQuo[1].isNegative() ? remQuo[0].prev() : remQuo[0];
n -= powers2Length - 1;
} remQuo = divModAny(result, powersOfTwo[n]); return remQuo[1].isNegative() ? remQuo[0].prev() : remQuo[0]; };
NativeBigInt.prototype.shiftRight = SmallInteger.prototype.shiftRight = BigInteger.prototype.shiftRight;
function bitwise(x, y, fn) { y = parseValue(y); var xSign = x.isNegative(), ySign = y.isNegative(); var xRem = xSign ? x.not() : x, yRem = ySign ? y.not() : y; var xDigit = 0, yDigit = 0; var xDivMod = null, yDivMod = null; var result = []; while (!xRem.isZero() || !yRem.isZero()) {
xDivMod = divModAny(xRem, highestPower2);
xDigit = xDivMod[1].toJSNumber();
if (xSign) {
xDigit = highestPower2 - 1 - xDigit;
}
yDivMod = divModAny(yRem, highestPower2);
yDigit = yDivMod[1].toJSNumber();
if (ySign) {
yDigit = highestPower2 - 1 - yDigit;
}
xRem = xDivMod[0];
yRem = yDivMod[0];
result.push(fn(xDigit, yDigit));
} var sum = fn(xSign ? 1 : 0, ySign ? 1 : 0) !== 0 ? bigInt(-1) : bigInt(0); for (var i = result.length - 1; i >= 0; i -= 1) {
sum = sum.multiply(highestPower2).add(bigInt(result[i]));
} return sum; }
BigInteger.prototype.not = function () { return this.negate().prev(); };
NativeBigInt.prototype.not = SmallInteger.prototype.not = BigInteger.prototype.not;
BigInteger.prototype.and = function (n) { return bitwise(this, n, function (a, b) { return a & b; }); };
NativeBigInt.prototype.and = SmallInteger.prototype.and = BigInteger.prototype.and;
BigInteger.prototype.or = function (n) { return bitwise(this, n, function (a, b) { return a | b; }); };
NativeBigInt.prototype.or = SmallInteger.prototype.or = BigInteger.prototype.or;
BigInteger.prototype.xor = function (n) { return bitwise(this, n, function (a, b) { return a ^ b; }); };
NativeBigInt.prototype.xor = SmallInteger.prototype.xor = BigInteger.prototype.xor;
var LOBMASK_I = 1 << 30, LOBMASK_BI = (BASE & -BASE) * (BASE & -BASE) | LOBMASK_I;
function roughLOB(n) { var v = n.value, x = typeof v === "number" ? v | LOBMASK_I : typeof v === "bigint" ? v | BigInt(LOBMASK_I) : v[0] + v[1] * BASE | LOBMASK_BI; return x & -x; }
function integerLogarithm(value, base) { if (base.compareTo(value) <= 0) {
var tmp = integerLogarithm(value, base.square(base));
var p = tmp.p;
var e = tmp.e;
var t = p.multiply(base);
return t.compareTo(value) <= 0 ? { p: t, e: e * 2 + 1 } : { p: p, e: e * 2 };
} return { p: bigInt(1), e: 0 }; }
BigInteger.prototype.bitLength = function () { var n = this; if (n.compareTo(bigInt(0)) < 0) {
n = n.negate().subtract(bigInt(1));
} if (n.compareTo(bigInt(0)) === 0) {
return bigInt(0);
} return bigInt(integerLogarithm(n, bigInt(2)).e).add(bigInt(1)); };
NativeBigInt.prototype.bitLength = SmallInteger.prototype.bitLength = BigInteger.prototype.bitLength;
function max(a, b) { a = parseValue(a); b = parseValue(b); return a.greater(b) ? a : b; }
function min(a, b) { a = parseValue(a); b = parseValue(b); return a.lesser(b) ? a : b; }
function gcd(a, b) { a = parseValue(a).abs(); b = parseValue(b).abs(); if (a.equals(b))
return a; if (a.isZero())
return b; if (b.isZero())
return a; var c = Integer[1], d, t; while (a.isEven() && b.isEven()) {
d = min(roughLOB(a), roughLOB(b));
a = a.divide(d);
b = b.divide(d);
c = c.multiply(d);
} while (a.isEven()) {
a = a.divide(roughLOB(a));
} do {
while (b.isEven()) {
b = b.divide(roughLOB(b));
}
if (a.greater(b)) {
t = b;
b = a;
a = t;
}
b = b.subtract(a);
} while (!b.isZero()); return c.isUnit() ? a : a.multiply(c); }
function lcm(a, b) { a = parseValue(a).abs(); b = parseValue(b).abs(); return a.divide(gcd(a, b)).multiply(b); }
function randBetween(a, b) { a = parseValue(a); b = parseValue(b); var low = min(a, b), high = max(a, b); var range = high.subtract(low).add(1); if (range.isSmall)
return low.add(Math.floor(Math.random() * range)); var digits = toBase(range, BASE).value; var result = [], restricted = true; for (var i = 0; i < digits.length; i++) {
var top = restricted ? digits[i] : BASE;
var digit = truncate(Math.random() * top);
result.push(digit);
if (digit < top)
restricted = false;
} return low.add(Integer.fromArray(result, BASE, false)); }
var parseBase = function (text, base, alphabet, caseSensitive) { alphabet = alphabet || DEFAULT_ALPHABET; text = String(text); if (!caseSensitive) {
text = text.toLowerCase();
alphabet = alphabet.toLowerCase();
} var length = text.length; var i; var absBase = Math.abs(base); var alphabetValues = {}; for (i = 0; i < alphabet.length; i++) {
alphabetValues[alphabet[i]] = i;
} for (i = 0; i < length; i++) {
var c = text[i];
if (c === "-")
continue;
if (c in alphabetValues) {
if (alphabetValues[c] >= absBase) {
if (c === "1" && absBase === 1)
continue;
throw new Error(c + " is not a valid digit in base " + base + ".");
}
}
} base = parseValue(base); var digits = []; var isNegative = text[0] === "-"; for (i = isNegative ? 1 : 0; i < text.length; i++) {
var c = text[i];
if (c in alphabetValues)
digits.push(parseValue(alphabetValues[c]));
else if (c === "<") {
var start = i;
do {
i++;
} while (text[i] !== ">" && i < text.length);
digits.push(parseValue(text.slice(start + 1, i)));
}
else
throw new Error(c + " is not a valid character");
} return parseBaseFromArray(digits, base, isNegative); };
function parseBaseFromArray(digits, base, isNegative) { var val = Integer[0], pow = Integer[1], i; for (i = digits.length - 1; i >= 0; i--) {
val = val.add(digits[i].times(pow));
pow = pow.times(base);
} return isNegative ? val.negate() : val; }
function stringify(digit, alphabet) { alphabet = alphabet || DEFAULT_ALPHABET; if (digit < alphabet.length) {
return alphabet[digit];
} return "<" + digit + ">"; }
function toBase(n, base) { base = bigInt(base); if (base.isZero()) {
if (n.isZero())
return { value: [0], isNegative: false };
throw new Error("Cannot convert nonzero numbers to base 0.");
} if (base.equals(-1)) {
if (n.isZero())
return { value: [0], isNegative: false };
if (n.isNegative())
return { value: [].concat.apply([], Array.apply(null, Array(-n.toJSNumber())).map(Array.prototype.valueOf, [1, 0])), isNegative: false };
var arr = Array.apply(null, Array(n.toJSNumber() - 1)).map(Array.prototype.valueOf, [0, 1]);
arr.unshift([1]);
return { value: [].concat.apply([], arr), isNegative: false };
} var neg = false; if (n.isNegative() && base.isPositive()) {
neg = true;
n = n.abs();
} if (base.isUnit()) {
if (n.isZero())
return { value: [0], isNegative: false };
return { value: Array.apply(null, Array(n.toJSNumber())).map(Number.prototype.valueOf, 1), isNegative: neg };
} var out = []; var left = n, divmod; while (left.isNegative() || left.compareAbs(base) >= 0) {
divmod = left.divmod(base);
left = divmod.quotient;
var digit = divmod.remainder;
if (digit.isNegative()) {
digit = base.minus(digit).abs();
left = left.next();
}
out.push(digit.toJSNumber());
} out.push(left.toJSNumber()); return { value: out.reverse(), isNegative: neg }; }
function toBaseString(n, base, alphabet) { var arr = toBase(n, base); return (arr.isNegative ? "-" : "") + arr.value.map(function (x) { return stringify(x, alphabet); }).join(""); }
BigInteger.prototype.toArray = function (radix) { return toBase(this, radix); };
SmallInteger.prototype.toArray = function (radix) { return toBase(this, radix); };
NativeBigInt.prototype.toArray = function (radix) { return toBase(this, radix); };
BigInteger.prototype.toString = function (radix, alphabet) { if (radix === undefined)
radix = 10; if (radix !== 10)
return toBaseString(this, radix, alphabet); var v = this.value, l = v.length, str = String(v[--l]), zeros = "0000000", digit; while (--l >= 0) {
digit = String(v[l]);
str += zeros.slice(digit.length) + digit;
} var sign = this.sign ? "-" : ""; return sign + str; };
SmallInteger.prototype.toString = function (radix, alphabet) { if (radix === undefined)
radix = 10; if (radix != 10)
return toBaseString(this, radix, alphabet); return String(this.value); };
NativeBigInt.prototype.toString = SmallInteger.prototype.toString;
NativeBigInt.prototype.toJSON = BigInteger.prototype.toJSON = SmallInteger.prototype.toJSON = function () { return this.toString(); };
BigInteger.prototype.valueOf = function () { return parseInt(this.toString(), 10); };
BigInteger.prototype.toJSNumber = BigInteger.prototype.valueOf;
SmallInteger.prototype.valueOf = function () { return this.value; };
SmallInteger.prototype.toJSNumber = SmallInteger.prototype.valueOf;
NativeBigInt.prototype.valueOf = NativeBigInt.prototype.toJSNumber = function () { return parseInt(this.toString(), 10); };
function parseStringValue(v) { if (isPrecise(+v)) {
var x = +v;
if (x === truncate(x))
return supportsNativeBigInt ? new NativeBigInt(BigInt(x)) : new SmallInteger(x);
throw new Error("Invalid integer: " + v);
} var sign = v[0] === "-"; if (sign)
v = v.slice(1); var split = v.split(/e/i); if (split.length > 2)
throw new Error("Invalid integer: " + split.join("e")); if (split.length === 2) {
var exp = split[1];
if (exp[0] === "+")
exp = exp.slice(1);
exp = +exp;
if (exp !== truncate(exp) || !isPrecise(exp))
throw new Error("Invalid integer: " + exp + " is not a valid exponent.");
var text = split[0];
var decimalPlace = text.indexOf(".");
if (decimalPlace >= 0) {
exp -= text.length - decimalPlace - 1;
text = text.slice(0, decimalPlace) + text.slice(decimalPlace + 1);
}
if (exp < 0)
throw new Error("Cannot include negative exponent part for integers");
text += new Array(exp + 1).join("0");
v = text;
} var isValid = /^([0-9][0-9]*)$/.test(v); if (!isValid)
throw new Error("Invalid integer: " + v); if (supportsNativeBigInt) {
return new NativeBigInt(BigInt(sign ? "-" + v : v));
} var r = [], max = v.length, l = LOG_BASE, min = max - l; while (max > 0) {
r.push(+v.slice(min, max));
min -= l;
if (min < 0)
min = 0;
max -= l;
} trim(r); return new BigInteger(r, sign); }
function parseNumberValue(v) { if (supportsNativeBigInt) {
return new NativeBigInt(BigInt(v));
} if (isPrecise(v)) {
if (v !== truncate(v))
throw new Error(v + " is not an integer.");
return new SmallInteger(v);
} return parseStringValue(v.toString()); }
function parseValue(v) { if (typeof v === "number") {
return parseNumberValue(v);
} if (typeof v === "string") {
return parseStringValue(v);
} if (typeof v === "bigint") {
return new NativeBigInt(v);
} return v; }
for (var i = 0; i < 1e3; i++) {
Integer[i] = parseValue(i);
if (i > 0)
Integer[-i] = parseValue(-i);
}
Integer.one = Integer[1];
Integer.zero = Integer[0];
Integer.minusOne = Integer[-1];
Integer.max = max;
Integer.min = min;
Integer.gcd = gcd;
Integer.lcm = lcm;
Integer.isInstance = function (x) { return x instanceof BigInteger || x instanceof SmallInteger || x instanceof NativeBigInt; };
Integer.randBetween = randBetween;
Integer.fromArray = function (digits, base, isNegative) { return parseBaseFromArray(digits.map(parseValue), parseValue(base || 10), isNegative); };
return Integer;
}();
if (typeof module !== "undefined" && module.hasOwnProperty("exports")) {
module.exports = bigInt;
}
if (typeof define === "function" && define.amd) {
define("big-integer", [], function () { return bigInt; });
}

8
dist/lib/Snowflake/snowflakey.js vendored Normal file
View File

@@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Master = require('./Master').default;
exports.Worker = require('./Worker').default;
exports.lookup = (flake, epoch) => {
return new Date((flake / 4194304) + epoch).toLocaleString();
};
exports.Token = require('./Token').default;

2
dist/lib/Snowflake/types.js vendored Normal file
View File

@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

8
dist/lib/Snowflake/util.js vendored Normal file
View File

@@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.sleep = (duration = 1) => {
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, (duration * 1000));
};
exports.getBits = (bits) => {
return (2 ** bits) - 1;
};

51
dist/lib/Token.js vendored Normal file
View File

@@ -0,0 +1,51 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const crypto_1 = require("crypto");
const otp_1 = __importDefault(require("./otp"));
class TokenGenerator {
constructor(secret, epoch = 1546300800000, seed = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz!@#$-', version = 1) {
this.EPOCH = epoch;
this.secret = secret;
this.VERSION = version;
this._otp = new otp_1.default(seed);
}
generate(ID) {
const parts = [
Buffer.from(ID).toString('base64'),
Buffer.from(this.tokenTime.toString()).toString('base64')
];
return `${parts.join('.').replace(/=/g, '')}.${this._computeHmac(parts.join('.').replace(/=/g, ''))}`;
}
upgrade(token, mfa, secret, counter = -1) {
if (!token.startsWith('mfa.') &&
((counter === -1 && this._otp.validateTotp(mfa, secret)) ||
(counter !== -1 && this._otp.validateHotp(mfa, secret, counter)))) {
const parts = token.split('.');
return `mfa.${parts[0]}.${parts[1]}.${this._computeHmac(`mfa.${parts[0]}.${parts[1]}`)}`;
}
return null;
}
validate(token, fetcher) {
const isMfa = token.startsWith('mfa.');
const partitions = token.replace(/^mfa\./, '').split('.');
if (partitions.length !== 3)
return false;
const signatureStr = `${isMfa ? 'mfa.' : ''}${partitions[0]}.${partitions[1]}`;
if (partitions[2] !== this._computeHmac(signatureStr))
return false;
const ID = Buffer.from(partitions[0], 'base64').toString('utf8');
const time = Buffer.from(partitions[1], 'base64').toString('utf8');
const accountDetails = fetcher(ID);
return time > accountDetails.tokensValidSince && isMfa === accountDetails.hasMfa;
}
get tokenTime() {
return Math.floor((Date.now() - this.EPOCH) / 1000);
}
_computeHmac(string) {
return crypto_1.createHmac('sha256', this.secret).update(`TTF.${this.VERSION}.${string}`).digest('base64').replace(/=/g, '');
}
}
exports.default = TokenGenerator;

51
dist/lib/Token/Token.js vendored Normal file
View File

@@ -0,0 +1,51 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const crypto_1 = require("crypto");
const otp_1 = __importDefault(require("./otp"));
class TokenGenerator {
constructor(secret, epoch = 1546300800000, seed = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz!@#$-', version = 1) {
this.EPOCH = epoch;
this.secret = secret;
this.VERSION = version;
this._otp = new otp_1.default(seed);
}
generate(ID) {
const parts = [
Buffer.from(ID).toString('base64'),
Buffer.from(this.tokenTime.toString()).toString('base64')
];
return `${parts.join('.').replace(/=/g, '')}.${this._computeHmac(parts.join('.').replace(/=/g, ''))}`;
}
upgrade(token, mfa, secret, counter = -1) {
if (!token.startsWith('mfa.') &&
((counter === -1 && this._otp.validateTotp(mfa, secret)) ||
(counter !== -1 && this._otp.validateHotp(mfa, secret, counter)))) {
const parts = token.split('.');
return `mfa.${parts[0]}.${parts[1]}.${this._computeHmac(`mfa.${parts[0]}.${parts[1]}`)}`;
}
return null;
}
validate(token, fetcher) {
const isMfa = token.startsWith('mfa.');
const partitions = token.replace(/^mfa\./, '').split('.');
if (partitions.length !== 3)
return false;
const signatureStr = `${isMfa ? 'mfa.' : ''}${partitions[0]}.${partitions[1]}`;
if (partitions[2] !== this._computeHmac(signatureStr))
return false;
const ID = Buffer.from(partitions[0], 'base64').toString('utf8');
const time = Buffer.from(partitions[1], 'base64').toString('utf8');
const accountDetails = fetcher(ID);
return time > accountDetails.tokensValidSince && isMfa === accountDetails.hasMfa;
}
get tokenTime() {
return Math.floor((Date.now() - this.EPOCH) / 1000);
}
_computeHmac(string) {
return crypto_1.createHmac('sha256', this.secret).update(`TTF.${this.VERSION}.${string}`).digest('base64').replace(/=/g, '');
}
}
exports.default = TokenGenerator;

67
dist/lib/Token/base32.js vendored Normal file
View File

@@ -0,0 +1,67 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class Base32 {
static encode(data) {
let encoded = '';
let shift = 3;
let carry = 0;
let symbol;
let byte;
for (let i = 0; i < data.length; i++) {
byte = data[i];
symbol = carry | (byte >> shift);
encoded += Base32.alphabet[symbol & 0x1f];
if (shift > 5) {
shift -= 5;
symbol = byte >> shift;
encoded += Base32.alphabet[symbol & 0x1f];
}
shift = 5 - shift;
carry = byte << shift;
shift = 8 - shift;
}
if (shift !== 3)
encoded += Base32.alphabet[carry & 0x1f];
return encoded;
}
static decode(data) {
Base32._charmap();
let shift = 8;
let carry = 0;
const chunks = [];
for (const char of data.toUpperCase().split('')) {
if (char === '')
return;
const symbol = Base32.charmap[char] & 0xff;
shift -= 5;
if (shift > 0)
carry |= symbol << shift;
else if (shift < 0) {
chunks.push(carry | (symbol >> -shift));
shift += 8;
carry = (symbol << shift) & 0xff;
}
else {
chunks.push(carry | symbol);
shift = 8;
carry = 0;
}
}
if (shift !== 8 && carry !== 0)
chunks.push(carry);
return Buffer.from(chunks);
}
static _charmap() {
if (!Base32.charmap) {
const mappings = { 0: 14, 1: 8 };
const alphabet = Base32.alphabet.split('');
for (const i in alphabet)
if (!(alphabet[i] in mappings))
mappings[alphabet[i]] = i;
Base32.charmap = mappings;
}
}
}
Base32.charmap = null;
Base32.alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
exports.default = Base32;

51
dist/lib/Token/main.js vendored Normal file
View File

@@ -0,0 +1,51 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const crypto_1 = require("crypto");
const otp_1 = __importDefault(require("./otp"));
class TokenGenerator {
constructor(options) {
this.EPOCH = options.epoch || 1546300800000;
this.secret = options.secret;
this.VERSION = options.version || 1;
this._otp = new otp_1.default(options.seed || '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz!@#$-');
}
generate(ID) {
const parts = [
Buffer.from(ID).toString('base64'),
Buffer.from(this.tokenTime.toString()).toString('base64')
];
return `${parts.join('.').replace(/=/g, '')}.${this._computeHmac(parts.join('.').replace(/=/g, ''))}`;
}
upgrade(token, mfa, secret, counter = -1) {
if (!token.startsWith('mfa.') &&
((counter === -1 && this._otp.validateTotp(mfa, secret)) ||
(counter !== -1 && this._otp.validateHotp(mfa, secret, counter)))) {
const parts = token.split('.');
return `mfa.${parts[0]}.${parts[1]}.${this._computeHmac(`mfa.${parts[0]}.${parts[1]}`)}`;
}
return null;
}
validate(token, fetcher) {
const isMfa = token.startsWith('mfa.');
const partitions = token.replace(/^mfa\./, '').split('.');
if (partitions.length !== 3)
return false;
const signatureStr = `${isMfa ? 'mfa.' : ''}${partitions[0]}.${partitions[1]}`;
if (partitions[2] !== this._computeHmac(signatureStr))
return false;
const ID = Buffer.from(partitions[0], 'base64').toString('utf8');
const time = Buffer.from(partitions[1], 'base64').toString('utf8');
const accountDetails = fetcher(ID);
return time > accountDetails.tokensValidSince && isMfa === accountDetails.hasMfa;
}
get tokenTime() {
return Math.floor((Date.now() - this.EPOCH) / 1000);
}
_computeHmac(string) {
return crypto_1.createHmac('sha256', this.secret).update(`TTF.${this.VERSION}.${string}`).digest('base64').replace(/=/g, '');
}
}
exports.default = TokenGenerator;

54
dist/lib/Token/otp.js vendored Normal file
View File

@@ -0,0 +1,54 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const base32_1 = __importDefault(require("./base32"));
const crypto_1 = require("crypto");
class OTP {
constructor(seed = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz!@#$-') {
this.seed = seed;
}
validateHotp(token, secret, counter) {
const counterInt = parseInt(counter, 10) || 0;
if (!secret || !token || token.length !== 6 || isNaN(parseInt(token, 10)))
return false;
return this._computeHotp(secret, counterInt) === token;
}
validateTotp(token, secret) {
return this.validateHotp(token, secret, Math.floor(Date.now() / 30 / 1000));
}
generateKey(name = 'Secret Key', issuer = null, hotp = false) {
const bytes = crypto_1.randomBytes(32);
const string = Array(32)
.fill(i => this.seed[Math.floor(bytes[i] / 255.0 * (this.seed.length - 1))])
.map((f, i) => f(i));
const key = {
raw: string.join(''),
base32: base32_1.default.encode(string)
};
return Object.defineProperty(key, 'url', {
value: 'google_url',
writable: false,
get: () => `otpauth://${hotp ? 'h' : 't'}otp/${name}?secret=${key.base32}${issuer ? `&issuer=${issuer}` : ''}`
});
}
_computeHotp(secret, counter) {
secret = base32_1.default.decode(secret);
let tmp = counter;
const chunks = Buffer.alloc(8);
for (let i = 0; i < 8; i++) {
chunks[7 - i] = tmp & 0xff;
tmp = tmp >> 8;
}
const digest = crypto_1.createHmac('sha1', secret).update(chunks).digest();
const offset = digest[digest.length - 1] & 0xf;
let code = (digest[offset] & 0x7f) << 24 |
(digest[offset + 1] & 0xff) << 16 |
(digest[offset + 2] & 0xff) << 8 |
(digest[offset + 3] & 0xff);
code = new Array(7).join('0') + code.toString(10);
return code.substr(-6);
}
}
exports.default = OTP;

121
dist/lib/Worker.js vendored Normal file
View File

@@ -0,0 +1,121 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const bigInt_1 = __importDefault(require("./bigInt"));
const events_1 = require("events");
const util_1 = require("./util");
class SnowflakeWorker extends events_1.EventEmitter {
constructor(options) {
super();
this.setMaxListeners(100);
this.options = {
name: undefined,
async: false,
epoch: null,
workerId: 0,
processId: 0,
stringify: true,
workerBits: 5,
processBits: 5,
incrementBits: 12,
...options
};
this._mutable = {
locks: [],
locked: false,
increment: bigInt_1.default.zero.subtract(1),
lastTimestamp: Date.now()
};
if (this.options.incrementBits + this.options.processBits + this.options.workerBits !== 22)
throw new Error('incrementBits, processBits, and workerBits must add up to 22.');
this.options.workerId = this.options.workerId % (2 ** this.options.workerBits);
this.options.processId = this.options.processId % (2 ** this.options.processBits);
if (isNaN(this.options.workerId))
this.options.workerId = 0;
if (isNaN(this.options.processId))
this.options.processId = 0;
this._maxIncrement = 2 ** this.options.incrementBits;
this.workerId = bigInt_1.default(this.options.workerId).shiftLeft(this.options.incrementBits + this.options.processBits);
this.processId = bigInt_1.default(this.options.processId).shiftLeft(this.options.incrementBits);
Object.freeze(this.options);
}
get increment() {
return this._mutable.increment = this._mutable.increment.next().mod(this._maxIncrement);
}
generate() {
if (this.options.async)
return this._generateAsync();
else
return this._generate();
}
_generate(date = Date.now(), increment = this.increment) {
let flake = bigInt_1.default(date).minus(this.options.epoch).shiftLeft(22)
.add(this.workerId)
.add(this.processId)
.add(increment);
this.emit('newSnowflake', {
worker: this,
method: 'sync',
snowflake: flake.toString(),
});
if (this.options.stringify)
flake = flake.toString();
return flake;
}
_lock() {
if (this._mutable.locked)
return new Promise(res => this._mutable.locks.push(res));
else
this._mutable.locked = true;
}
_unlock() {
if (this._mutable.locks.length > 0)
this._mutable.locks.shift()();
else
this._mutable.locked = false;
}
async _generateAsync() {
let lock = this._lock();
if (lock)
await lock;
let now = Date.now();
if (this._mutable.lastTimestamp !== now) {
this._mutable.increment = bigInt_1.default.zero;
this._mutable.lastTimestamp = now;
}
else {
this._mutable.increment = this._mutable.increment.next();
if (this._mutable.increment.greaterOrEquals(this._maxIncrement)) {
await util_1.sleep(2 / 1000);
this._mutable.increment = bigInt_1.default.zero;
now = this._mutable.lastTimestamp = Date.now();
}
}
let flake = this._generate(now, this._mutable.increment);
this._unlock();
this.emit('newSnowflake', {
worker: this,
method: 'async',
snowflake: flake.toString(),
});
return flake;
}
deconstruct(snowflake) {
let flake = bigInt_1.default(snowflake);
let timestamp = flake.shiftRight(22).add(this.options.epoch);
let wBitShift = this.options.incrementBits + this.options.processBits;
let workerId = flake.and(bigInt_1.default(util_1.getBits(this.options.workerBits)).shiftLeft(wBitShift)).shiftRight(wBitShift);
let processId = flake.and(bigInt_1.default(util_1.getBits(this.options.processBits)).shiftLeft(this.options.incrementBits)).shiftRight(this.options.incrementBits);
let increment = flake.and(util_1.getBits(this.options.incrementBits));
this.emit('deconstructedFlake', {
worker: this,
method: 'sync',
timestamp, workerId, processId, increment
});
return { timestamp, workerId, processId, increment };
}
}
exports.default = SnowflakeWorker;
;

66
dist/lib/base32.js vendored Normal file
View File

@@ -0,0 +1,66 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class Base32 {
static encode(data) {
let encoded = '';
let shift = 3;
let carry = 0;
let symbol, byte;
for (let i = 0; i < data.length; i++) {
byte = data[i];
symbol = carry | (byte >> shift);
encoded += Base32.alphabet[symbol & 0x1f];
if (shift > 5) {
shift -= 5;
symbol = byte >> shift;
encoded += Base32.alphabet[symbol & 0x1f];
}
shift = 5 - shift;
carry = byte << shift;
shift = 8 - shift;
}
if (shift !== 3)
encoded += Base32.alphabet[carry & 0x1f];
return encoded;
}
static decode(data) {
Base32._charmap();
let shift = 8;
let carry = 0;
const chunks = [];
for (const char of data.toUpperCase().split('')) {
if (char === '')
return;
const symbol = Base32.charmap[char] & 0xff;
shift -= 5;
if (shift > 0)
carry |= symbol << shift;
else if (shift < 0) {
chunks.push(carry | (symbol >> -shift));
shift += 8;
carry = (symbol << shift) & 0xff;
}
else {
chunks.push(carry | symbol);
shift = 8;
carry = 0;
}
}
if (shift !== 8 && carry !== 0)
chunks.push(carry);
return Buffer.from(chunks);
}
static _charmap() {
if (!Base32.charmap) {
const mappings = { 0: 14, 1: 8 };
const alphabet = Base32.alphabet.split('');
for (const i in alphabet)
if (!(alphabet[i] in mappings))
mappings[alphabet[i]] = i;
Base32.charmap = mappings;
}
}
}
Base32.charmap = null;
Base32.alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
exports.default = Base32;

747
dist/lib/bigInt.js vendored Normal file
View File

@@ -0,0 +1,747 @@
var bigInt = function (undefined) {
"use strict";
var BASE = 1e7, LOG_BASE = 7, MAX_INT = 9007199254740992, MAX_INT_ARR = smallToArray(MAX_INT), DEFAULT_ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyz";
var supportsNativeBigInt = typeof BigInt === "function";
function Integer(v, radix, alphabet, caseSensitive) { if (typeof v === "undefined")
return Integer[0]; if (typeof radix !== "undefined")
return +radix === 10 && !alphabet ? parseValue(v) : parseBase(v, radix, alphabet, caseSensitive); return parseValue(v); }
function BigInteger(value, sign) { this.value = value; this.sign = sign; this.isSmall = false; }
BigInteger.prototype = Object.create(Integer.prototype);
function SmallInteger(value) { this.value = value; this.sign = value < 0; this.isSmall = true; }
SmallInteger.prototype = Object.create(Integer.prototype);
function NativeBigInt(value) { this.value = value; }
NativeBigInt.prototype = Object.create(Integer.prototype);
function isPrecise(n) { return -MAX_INT < n && n < MAX_INT; }
function smallToArray(n) { if (n < 1e7)
return [n]; if (n < 1e14)
return [n % 1e7, Math.floor(n / 1e7)]; return [n % 1e7, Math.floor(n / 1e7) % 1e7, Math.floor(n / 1e14)]; }
function arrayToSmall(arr) { trim(arr); var length = arr.length; if (length < 4 && compareAbs(arr, MAX_INT_ARR) < 0) {
switch (length) {
case 0: return 0;
case 1: return arr[0];
case 2: return arr[0] + arr[1] * BASE;
default: return arr[0] + (arr[1] + arr[2] * BASE) * BASE;
}
} return arr; }
function trim(v) { var i = v.length; while (v[--i] === 0)
; v.length = i + 1; }
function createArray(length) { var x = new Array(length); var i = -1; while (++i < length) {
x[i] = 0;
} return x; }
function truncate(n) { if (n > 0)
return Math.floor(n); return Math.ceil(n); }
function add(a, b) { var l_a = a.length, l_b = b.length, r = new Array(l_a), carry = 0, base = BASE, sum, i; for (i = 0; i < l_b; i++) {
sum = a[i] + b[i] + carry;
carry = sum >= base ? 1 : 0;
r[i] = sum - carry * base;
} while (i < l_a) {
sum = a[i] + carry;
carry = sum === base ? 1 : 0;
r[i++] = sum - carry * base;
} if (carry > 0)
r.push(carry); return r; }
function addAny(a, b) { if (a.length >= b.length)
return add(a, b); return add(b, a); }
function addSmall(a, carry) { var l = a.length, r = new Array(l), base = BASE, sum, i; for (i = 0; i < l; i++) {
sum = a[i] - base + carry;
carry = Math.floor(sum / base);
r[i] = sum - carry * base;
carry += 1;
} while (carry > 0) {
r[i++] = carry % base;
carry = Math.floor(carry / base);
} return r; }
BigInteger.prototype.add = function (v) { var n = parseValue(v); if (this.sign !== n.sign) {
return this.subtract(n.negate());
} var a = this.value, b = n.value; if (n.isSmall) {
return new BigInteger(addSmall(a, Math.abs(b)), this.sign);
} return new BigInteger(addAny(a, b), this.sign); };
BigInteger.prototype.plus = BigInteger.prototype.add;
SmallInteger.prototype.add = function (v) { var n = parseValue(v); var a = this.value; if (a < 0 !== n.sign) {
return this.subtract(n.negate());
} var b = n.value; if (n.isSmall) {
if (isPrecise(a + b))
return new SmallInteger(a + b);
b = smallToArray(Math.abs(b));
} return new BigInteger(addSmall(b, Math.abs(a)), a < 0); };
SmallInteger.prototype.plus = SmallInteger.prototype.add;
NativeBigInt.prototype.add = function (v) { return new NativeBigInt(this.value + parseValue(v).value); };
NativeBigInt.prototype.plus = NativeBigInt.prototype.add;
function subtract(a, b) { var a_l = a.length, b_l = b.length, r = new Array(a_l), borrow = 0, base = BASE, i, difference; for (i = 0; i < b_l; i++) {
difference = a[i] - borrow - b[i];
if (difference < 0) {
difference += base;
borrow = 1;
}
else
borrow = 0;
r[i] = difference;
} for (i = b_l; i < a_l; i++) {
difference = a[i] - borrow;
if (difference < 0)
difference += base;
else {
r[i++] = difference;
break;
}
r[i] = difference;
} for (; i < a_l; i++) {
r[i] = a[i];
} trim(r); return r; }
function subtractAny(a, b, sign) { var value; if (compareAbs(a, b) >= 0) {
value = subtract(a, b);
}
else {
value = subtract(b, a);
sign = !sign;
} value = arrayToSmall(value); if (typeof value === "number") {
if (sign)
value = -value;
return new SmallInteger(value);
} return new BigInteger(value, sign); }
function subtractSmall(a, b, sign) { var l = a.length, r = new Array(l), carry = -b, base = BASE, i, difference; for (i = 0; i < l; i++) {
difference = a[i] + carry;
carry = Math.floor(difference / base);
difference %= base;
r[i] = difference < 0 ? difference + base : difference;
} r = arrayToSmall(r); if (typeof r === "number") {
if (sign)
r = -r;
return new SmallInteger(r);
} return new BigInteger(r, sign); }
BigInteger.prototype.subtract = function (v) { var n = parseValue(v); if (this.sign !== n.sign) {
return this.add(n.negate());
} var a = this.value, b = n.value; if (n.isSmall)
return subtractSmall(a, Math.abs(b), this.sign); return subtractAny(a, b, this.sign); };
BigInteger.prototype.minus = BigInteger.prototype.subtract;
SmallInteger.prototype.subtract = function (v) { var n = parseValue(v); var a = this.value; if (a < 0 !== n.sign) {
return this.add(n.negate());
} var b = n.value; if (n.isSmall) {
return new SmallInteger(a - b);
} return subtractSmall(b, Math.abs(a), a >= 0); };
SmallInteger.prototype.minus = SmallInteger.prototype.subtract;
NativeBigInt.prototype.subtract = function (v) { return new NativeBigInt(this.value - parseValue(v).value); };
NativeBigInt.prototype.minus = NativeBigInt.prototype.subtract;
BigInteger.prototype.negate = function () { return new BigInteger(this.value, !this.sign); };
SmallInteger.prototype.negate = function () { var sign = this.sign; var small = new SmallInteger(-this.value); small.sign = !sign; return small; };
NativeBigInt.prototype.negate = function () { return new NativeBigInt(-this.value); };
BigInteger.prototype.abs = function () { return new BigInteger(this.value, false); };
SmallInteger.prototype.abs = function () { return new SmallInteger(Math.abs(this.value)); };
NativeBigInt.prototype.abs = function () { return new NativeBigInt(this.value >= 0 ? this.value : -this.value); };
function multiplyLong(a, b) { var a_l = a.length, b_l = b.length, l = a_l + b_l, r = createArray(l), base = BASE, product, carry, i, a_i, b_j; for (i = 0; i < a_l; ++i) {
a_i = a[i];
for (var j = 0; j < b_l; ++j) {
b_j = b[j];
product = a_i * b_j + r[i + j];
carry = Math.floor(product / base);
r[i + j] = product - carry * base;
r[i + j + 1] += carry;
}
} trim(r); return r; }
function multiplySmall(a, b) { var l = a.length, r = new Array(l), base = BASE, carry = 0, product, i; for (i = 0; i < l; i++) {
product = a[i] * b + carry;
carry = Math.floor(product / base);
r[i] = product - carry * base;
} while (carry > 0) {
r[i++] = carry % base;
carry = Math.floor(carry / base);
} return r; }
function shiftLeft(x, n) { var r = []; while (n-- > 0)
r.push(0); return r.concat(x); }
function multiplyKaratsuba(x, y) { var n = Math.max(x.length, y.length); if (n <= 30)
return multiplyLong(x, y); n = Math.ceil(n / 2); var b = x.slice(n), a = x.slice(0, n), d = y.slice(n), c = y.slice(0, n); var ac = multiplyKaratsuba(a, c), bd = multiplyKaratsuba(b, d), abcd = multiplyKaratsuba(addAny(a, b), addAny(c, d)); var product = addAny(addAny(ac, shiftLeft(subtract(subtract(abcd, ac), bd), n)), shiftLeft(bd, 2 * n)); trim(product); return product; }
function useKaratsuba(l1, l2) { return -.012 * l1 - .012 * l2 + 15e-6 * l1 * l2 > 0; }
BigInteger.prototype.multiply = function (v) { var n = parseValue(v), a = this.value, b = n.value, sign = this.sign !== n.sign, abs; if (n.isSmall) {
if (b === 0)
return Integer[0];
if (b === 1)
return this;
if (b === -1)
return this.negate();
abs = Math.abs(b);
if (abs < BASE) {
return new BigInteger(multiplySmall(a, abs), sign);
}
b = smallToArray(abs);
} if (useKaratsuba(a.length, b.length))
return new BigInteger(multiplyKaratsuba(a, b), sign); return new BigInteger(multiplyLong(a, b), sign); };
BigInteger.prototype.times = BigInteger.prototype.multiply;
function multiplySmallAndArray(a, b, sign) { if (a < BASE) {
return new BigInteger(multiplySmall(b, a), sign);
} return new BigInteger(multiplyLong(b, smallToArray(a)), sign); }
SmallInteger.prototype._multiplyBySmall = function (a) { if (isPrecise(a.value * this.value)) {
return new SmallInteger(a.value * this.value);
} return multiplySmallAndArray(Math.abs(a.value), smallToArray(Math.abs(this.value)), this.sign !== a.sign); };
BigInteger.prototype._multiplyBySmall = function (a) { if (a.value === 0)
return Integer[0]; if (a.value === 1)
return this; if (a.value === -1)
return this.negate(); return multiplySmallAndArray(Math.abs(a.value), this.value, this.sign !== a.sign); };
SmallInteger.prototype.multiply = function (v) { return parseValue(v)._multiplyBySmall(this); };
SmallInteger.prototype.times = SmallInteger.prototype.multiply;
NativeBigInt.prototype.multiply = function (v) { return new NativeBigInt(this.value * parseValue(v).value); };
NativeBigInt.prototype.times = NativeBigInt.prototype.multiply;
function square(a) { var l = a.length, r = createArray(l + l), base = BASE, product, carry, i, a_i, a_j; for (i = 0; i < l; i++) {
a_i = a[i];
carry = 0 - a_i * a_i;
for (var j = i; j < l; j++) {
a_j = a[j];
product = 2 * (a_i * a_j) + r[i + j] + carry;
carry = Math.floor(product / base);
r[i + j] = product - carry * base;
}
r[i + l] = carry;
} trim(r); return r; }
BigInteger.prototype.square = function () { return new BigInteger(square(this.value), false); };
SmallInteger.prototype.square = function () { var value = this.value * this.value; if (isPrecise(value))
return new SmallInteger(value); return new BigInteger(square(smallToArray(Math.abs(this.value))), false); };
NativeBigInt.prototype.square = function (v) { return new NativeBigInt(this.value * this.value); };
function divMod1(a, b) { var a_l = a.length, b_l = b.length, base = BASE, result = createArray(b.length), divisorMostSignificantDigit = b[b_l - 1], lambda = Math.ceil(base / (2 * divisorMostSignificantDigit)), remainder = multiplySmall(a, lambda), divisor = multiplySmall(b, lambda), quotientDigit, shift, carry, borrow, i, l, q; if (remainder.length <= a_l)
remainder.push(0); divisor.push(0); divisorMostSignificantDigit = divisor[b_l - 1]; for (shift = a_l - b_l; shift >= 0; shift--) {
quotientDigit = base - 1;
if (remainder[shift + b_l] !== divisorMostSignificantDigit) {
quotientDigit = Math.floor((remainder[shift + b_l] * base + remainder[shift + b_l - 1]) / divisorMostSignificantDigit);
}
carry = 0;
borrow = 0;
l = divisor.length;
for (i = 0; i < l; i++) {
carry += quotientDigit * divisor[i];
q = Math.floor(carry / base);
borrow += remainder[shift + i] - (carry - q * base);
carry = q;
if (borrow < 0) {
remainder[shift + i] = borrow + base;
borrow = -1;
}
else {
remainder[shift + i] = borrow;
borrow = 0;
}
}
while (borrow !== 0) {
quotientDigit -= 1;
carry = 0;
for (i = 0; i < l; i++) {
carry += remainder[shift + i] - base + divisor[i];
if (carry < 0) {
remainder[shift + i] = carry + base;
carry = 0;
}
else {
remainder[shift + i] = carry;
carry = 1;
}
}
borrow += carry;
}
result[shift] = quotientDigit;
} remainder = divModSmall(remainder, lambda)[0]; return [arrayToSmall(result), arrayToSmall(remainder)]; }
function divMod2(a, b) { var a_l = a.length, b_l = b.length, result = [], part = [], base = BASE, guess, xlen, highx, highy, check; while (a_l) {
part.unshift(a[--a_l]);
trim(part);
if (compareAbs(part, b) < 0) {
result.push(0);
continue;
}
xlen = part.length;
highx = part[xlen - 1] * base + part[xlen - 2];
highy = b[b_l - 1] * base + b[b_l - 2];
if (xlen > b_l) {
highx = (highx + 1) * base;
}
guess = Math.ceil(highx / highy);
do {
check = multiplySmall(b, guess);
if (compareAbs(check, part) <= 0)
break;
guess--;
} while (guess);
result.push(guess);
part = subtract(part, check);
} result.reverse(); return [arrayToSmall(result), arrayToSmall(part)]; }
function divModSmall(value, lambda) { var length = value.length, quotient = createArray(length), base = BASE, i, q, remainder, divisor; remainder = 0; for (i = length - 1; i >= 0; --i) {
divisor = remainder * base + value[i];
q = truncate(divisor / lambda);
remainder = divisor - q * lambda;
quotient[i] = q | 0;
} return [quotient, remainder | 0]; }
function divModAny(self, v) { var value, n = parseValue(v); if (supportsNativeBigInt) {
return [new NativeBigInt(self.value / n.value), new NativeBigInt(self.value % n.value)];
} var a = self.value, b = n.value; var quotient; if (b === 0)
throw new Error("Cannot divide by zero"); if (self.isSmall) {
if (n.isSmall) {
return [new SmallInteger(truncate(a / b)), new SmallInteger(a % b)];
}
return [Integer[0], self];
} if (n.isSmall) {
if (b === 1)
return [self, Integer[0]];
if (b == -1)
return [self.negate(), Integer[0]];
var abs = Math.abs(b);
if (abs < BASE) {
value = divModSmall(a, abs);
quotient = arrayToSmall(value[0]);
var remainder = value[1];
if (self.sign)
remainder = -remainder;
if (typeof quotient === "number") {
if (self.sign !== n.sign)
quotient = -quotient;
return [new SmallInteger(quotient), new SmallInteger(remainder)];
}
return [new BigInteger(quotient, self.sign !== n.sign), new SmallInteger(remainder)];
}
b = smallToArray(abs);
} var comparison = compareAbs(a, b); if (comparison === -1)
return [Integer[0], self]; if (comparison === 0)
return [Integer[self.sign === n.sign ? 1 : -1], Integer[0]]; if (a.length + b.length <= 200)
value = divMod1(a, b);
else
value = divMod2(a, b); quotient = value[0]; var qSign = self.sign !== n.sign, mod = value[1], mSign = self.sign; if (typeof quotient === "number") {
if (qSign)
quotient = -quotient;
quotient = new SmallInteger(quotient);
}
else
quotient = new BigInteger(quotient, qSign); if (typeof mod === "number") {
if (mSign)
mod = -mod;
mod = new SmallInteger(mod);
}
else
mod = new BigInteger(mod, mSign); return [quotient, mod]; }
BigInteger.prototype.divmod = function (v) { var result = divModAny(this, v); return { quotient: result[0], remainder: result[1] }; };
NativeBigInt.prototype.divmod = SmallInteger.prototype.divmod = BigInteger.prototype.divmod;
BigInteger.prototype.divide = function (v) { return divModAny(this, v)[0]; };
NativeBigInt.prototype.over = NativeBigInt.prototype.divide = SmallInteger.prototype.over = SmallInteger.prototype.divide = BigInteger.prototype.over = BigInteger.prototype.divide;
BigInteger.prototype.mod = function (v) { return divModAny(this, v)[1]; };
NativeBigInt.prototype.mod = NativeBigInt.prototype.remainder = SmallInteger.prototype.remainder = SmallInteger.prototype.mod = BigInteger.prototype.remainder = BigInteger.prototype.mod;
BigInteger.prototype.pow = function (v) { var n = parseValue(v), a = this.value, b = n.value, value, x, y; if (b === 0)
return Integer[1]; if (a === 0)
return Integer[0]; if (a === 1)
return Integer[1]; if (a === -1)
return n.isEven() ? Integer[1] : Integer[-1]; if (n.sign) {
return Integer[0];
} if (!n.isSmall)
throw new Error("The exponent " + n.toString() + " is too large."); if (this.isSmall) {
if (isPrecise(value = Math.pow(a, b)))
return new SmallInteger(truncate(value));
} x = this; y = Integer[1]; while (true) {
if (b & 1 === 1) {
y = y.times(x);
--b;
}
if (b === 0)
break;
b /= 2;
x = x.square();
} return y; };
SmallInteger.prototype.pow = BigInteger.prototype.pow;
var pow;
if (supportsNativeBigInt) {
pow = eval("(a,b)=>a**b");
}
NativeBigInt.prototype.pow = function (v) { var n = parseValue(v); var a = this.value, b = n.value; if (b === BigInt(0))
return Integer[1]; if (a === BigInt(0))
return Integer[0]; if (a === BigInt(1))
return Integer[1]; if (a === BigInt(-1))
return n.isEven() ? Integer[1] : Integer[-1]; if (n.isNegative())
return new NativeBigInt(BigInt(0)); return new NativeBigInt(pow(a, b)); };
BigInteger.prototype.modPow = function (exp, mod) { exp = parseValue(exp); mod = parseValue(mod); if (mod.isZero())
throw new Error("Cannot take modPow with modulus 0"); var r = Integer[1], base = this.mod(mod); while (exp.isPositive()) {
if (base.isZero())
return Integer[0];
if (exp.isOdd())
r = r.multiply(base).mod(mod);
exp = exp.divide(2);
base = base.square().mod(mod);
} return r; };
NativeBigInt.prototype.modPow = SmallInteger.prototype.modPow = BigInteger.prototype.modPow;
function compareAbs(a, b) { if (a.length !== b.length) {
return a.length > b.length ? 1 : -1;
} for (var i = a.length - 1; i >= 0; i--) {
if (a[i] !== b[i])
return a[i] > b[i] ? 1 : -1;
} return 0; }
BigInteger.prototype.compareAbs = function (v) { var n = parseValue(v), a = this.value, b = n.value; if (n.isSmall)
return 1; return compareAbs(a, b); };
SmallInteger.prototype.compareAbs = function (v) { var n = parseValue(v), a = Math.abs(this.value), b = n.value; if (n.isSmall) {
b = Math.abs(b);
return a === b ? 0 : a > b ? 1 : -1;
} return -1; };
NativeBigInt.prototype.compareAbs = function (v) { var a = this.value; var b = parseValue(v).value; a = a >= 0 ? a : -a; b = b >= 0 ? b : -b; return a === b ? 0 : a > b ? 1 : -1; };
BigInteger.prototype.compare = function (v) { if (v === Infinity) {
return -1;
} if (v === -Infinity) {
return 1;
} var n = parseValue(v), a = this.value, b = n.value; if (this.sign !== n.sign) {
return n.sign ? 1 : -1;
} if (n.isSmall) {
return this.sign ? -1 : 1;
} return compareAbs(a, b) * (this.sign ? -1 : 1); };
BigInteger.prototype.compareTo = BigInteger.prototype.compare;
SmallInteger.prototype.compare = function (v) { if (v === Infinity) {
return -1;
} if (v === -Infinity) {
return 1;
} var n = parseValue(v), a = this.value, b = n.value; if (n.isSmall) {
return a == b ? 0 : a > b ? 1 : -1;
} if (a < 0 !== n.sign) {
return a < 0 ? -1 : 1;
} return a < 0 ? 1 : -1; };
SmallInteger.prototype.compareTo = SmallInteger.prototype.compare;
NativeBigInt.prototype.compare = function (v) { if (v === Infinity) {
return -1;
} if (v === -Infinity) {
return 1;
} var a = this.value; var b = parseValue(v).value; return a === b ? 0 : a > b ? 1 : -1; };
NativeBigInt.prototype.compareTo = NativeBigInt.prototype.compare;
BigInteger.prototype.equals = function (v) { return this.compare(v) === 0; };
NativeBigInt.prototype.eq = NativeBigInt.prototype.equals = SmallInteger.prototype.eq = SmallInteger.prototype.equals = BigInteger.prototype.eq = BigInteger.prototype.equals;
BigInteger.prototype.notEquals = function (v) { return this.compare(v) !== 0; };
NativeBigInt.prototype.neq = NativeBigInt.prototype.notEquals = SmallInteger.prototype.neq = SmallInteger.prototype.notEquals = BigInteger.prototype.neq = BigInteger.prototype.notEquals;
BigInteger.prototype.greater = function (v) { return this.compare(v) > 0; };
NativeBigInt.prototype.gt = NativeBigInt.prototype.greater = SmallInteger.prototype.gt = SmallInteger.prototype.greater = BigInteger.prototype.gt = BigInteger.prototype.greater;
BigInteger.prototype.lesser = function (v) { return this.compare(v) < 0; };
NativeBigInt.prototype.lt = NativeBigInt.prototype.lesser = SmallInteger.prototype.lt = SmallInteger.prototype.lesser = BigInteger.prototype.lt = BigInteger.prototype.lesser;
BigInteger.prototype.greaterOrEquals = function (v) { return this.compare(v) >= 0; };
NativeBigInt.prototype.geq = NativeBigInt.prototype.greaterOrEquals = SmallInteger.prototype.geq = SmallInteger.prototype.greaterOrEquals = BigInteger.prototype.geq = BigInteger.prototype.greaterOrEquals;
BigInteger.prototype.lesserOrEquals = function (v) { return this.compare(v) <= 0; };
NativeBigInt.prototype.leq = NativeBigInt.prototype.lesserOrEquals = SmallInteger.prototype.leq = SmallInteger.prototype.lesserOrEquals = BigInteger.prototype.leq = BigInteger.prototype.lesserOrEquals;
BigInteger.prototype.isEven = function () { return (this.value[0] & 1) === 0; };
SmallInteger.prototype.isEven = function () { return (this.value & 1) === 0; };
NativeBigInt.prototype.isEven = function () { return (this.value & BigInt(1)) === BigInt(0); };
BigInteger.prototype.isOdd = function () { return (this.value[0] & 1) === 1; };
SmallInteger.prototype.isOdd = function () { return (this.value & 1) === 1; };
NativeBigInt.prototype.isOdd = function () { return (this.value & BigInt(1)) === BigInt(1); };
BigInteger.prototype.isPositive = function () { return !this.sign; };
SmallInteger.prototype.isPositive = function () { return this.value > 0; };
NativeBigInt.prototype.isPositive = SmallInteger.prototype.isPositive;
BigInteger.prototype.isNegative = function () { return this.sign; };
SmallInteger.prototype.isNegative = function () { return this.value < 0; };
NativeBigInt.prototype.isNegative = SmallInteger.prototype.isNegative;
BigInteger.prototype.isUnit = function () { return false; };
SmallInteger.prototype.isUnit = function () { return Math.abs(this.value) === 1; };
NativeBigInt.prototype.isUnit = function () { return this.abs().value === BigInt(1); };
BigInteger.prototype.isZero = function () { return false; };
SmallInteger.prototype.isZero = function () { return this.value === 0; };
NativeBigInt.prototype.isZero = function () { return this.value === BigInt(0); };
BigInteger.prototype.isDivisibleBy = function (v) { var n = parseValue(v); if (n.isZero())
return false; if (n.isUnit())
return true; if (n.compareAbs(2) === 0)
return this.isEven(); return this.mod(n).isZero(); };
NativeBigInt.prototype.isDivisibleBy = SmallInteger.prototype.isDivisibleBy = BigInteger.prototype.isDivisibleBy;
function isBasicPrime(v) { var n = v.abs(); if (n.isUnit())
return false; if (n.equals(2) || n.equals(3) || n.equals(5))
return true; if (n.isEven() || n.isDivisibleBy(3) || n.isDivisibleBy(5))
return false; if (n.lesser(49))
return true; }
function millerRabinTest(n, a) { var nPrev = n.prev(), b = nPrev, r = 0, d, t, i, x; while (b.isEven())
b = b.divide(2), r++; next: for (i = 0; i < a.length; i++) {
if (n.lesser(a[i]))
continue;
x = bigInt(a[i]).modPow(b, n);
if (x.isUnit() || x.equals(nPrev))
continue;
for (d = r - 1; d != 0; d--) {
x = x.square().mod(n);
if (x.isUnit())
return false;
if (x.equals(nPrev))
continue next;
}
return false;
} return true; }
BigInteger.prototype.isPrime = function (strict) { var isPrime = isBasicPrime(this); if (isPrime !== undefined)
return isPrime; var n = this.abs(); var bits = n.bitLength(); if (bits <= 64)
return millerRabinTest(n, [2, 325, 9375, 28178, 450775, 9780504, 1795265022]); var logN = Math.log(2) * bits.toJSNumber(); var t = Math.ceil(strict === true ? 2 * Math.pow(logN, 2) : logN); for (var a = [], i = 0; i < t; i++) {
a.push(bigInt(i + 2));
} return millerRabinTest(n, a); };
NativeBigInt.prototype.isPrime = SmallInteger.prototype.isPrime = BigInteger.prototype.isPrime;
BigInteger.prototype.isProbablePrime = function (iterations) { var isPrime = isBasicPrime(this); if (isPrime !== undefined)
return isPrime; var n = this.abs(); var t = iterations === undefined ? 5 : iterations; for (var a = [], i = 0; i < t; i++) {
a.push(bigInt.randBetween(2, n.minus(2)));
} return millerRabinTest(n, a); };
NativeBigInt.prototype.isProbablePrime = SmallInteger.prototype.isProbablePrime = BigInteger.prototype.isProbablePrime;
BigInteger.prototype.modInv = function (n) { var t = bigInt.zero, newT = bigInt.one, r = parseValue(n), newR = this.abs(), q, lastT, lastR; while (!newR.isZero()) {
q = r.divide(newR);
lastT = t;
lastR = r;
t = newT;
r = newR;
newT = lastT.subtract(q.multiply(newT));
newR = lastR.subtract(q.multiply(newR));
} if (!r.isUnit())
throw new Error(this.toString() + " and " + n.toString() + " are not co-prime"); if (t.compare(0) === -1) {
t = t.add(n);
} if (this.isNegative()) {
return t.negate();
} return t; };
NativeBigInt.prototype.modInv = SmallInteger.prototype.modInv = BigInteger.prototype.modInv;
BigInteger.prototype.next = function () { var value = this.value; if (this.sign) {
return subtractSmall(value, 1, this.sign);
} return new BigInteger(addSmall(value, 1), this.sign); };
SmallInteger.prototype.next = function () { var value = this.value; if (value + 1 < MAX_INT)
return new SmallInteger(value + 1); return new BigInteger(MAX_INT_ARR, false); };
NativeBigInt.prototype.next = function () { return new NativeBigInt(this.value + BigInt(1)); };
BigInteger.prototype.prev = function () { var value = this.value; if (this.sign) {
return new BigInteger(addSmall(value, 1), true);
} return subtractSmall(value, 1, this.sign); };
SmallInteger.prototype.prev = function () { var value = this.value; if (value - 1 > -MAX_INT)
return new SmallInteger(value - 1); return new BigInteger(MAX_INT_ARR, true); };
NativeBigInt.prototype.prev = function () { return new NativeBigInt(this.value - BigInt(1)); };
var powersOfTwo = [1];
while (2 * powersOfTwo[powersOfTwo.length - 1] <= BASE)
powersOfTwo.push(2 * powersOfTwo[powersOfTwo.length - 1]);
var powers2Length = powersOfTwo.length, highestPower2 = powersOfTwo[powers2Length - 1];
function shift_isSmall(n) { return Math.abs(n) <= BASE; }
BigInteger.prototype.shiftLeft = function (v) { var n = parseValue(v).toJSNumber(); if (!shift_isSmall(n)) {
throw new Error(String(n) + " is too large for shifting.");
} if (n < 0)
return this.shiftRight(-n); var result = this; if (result.isZero())
return result; while (n >= powers2Length) {
result = result.multiply(highestPower2);
n -= powers2Length - 1;
} return result.multiply(powersOfTwo[n]); };
NativeBigInt.prototype.shiftLeft = SmallInteger.prototype.shiftLeft = BigInteger.prototype.shiftLeft;
BigInteger.prototype.shiftRight = function (v) { var remQuo; var n = parseValue(v).toJSNumber(); if (!shift_isSmall(n)) {
throw new Error(String(n) + " is too large for shifting.");
} if (n < 0)
return this.shiftLeft(-n); var result = this; while (n >= powers2Length) {
if (result.isZero() || result.isNegative() && result.isUnit())
return result;
remQuo = divModAny(result, highestPower2);
result = remQuo[1].isNegative() ? remQuo[0].prev() : remQuo[0];
n -= powers2Length - 1;
} remQuo = divModAny(result, powersOfTwo[n]); return remQuo[1].isNegative() ? remQuo[0].prev() : remQuo[0]; };
NativeBigInt.prototype.shiftRight = SmallInteger.prototype.shiftRight = BigInteger.prototype.shiftRight;
function bitwise(x, y, fn) { y = parseValue(y); var xSign = x.isNegative(), ySign = y.isNegative(); var xRem = xSign ? x.not() : x, yRem = ySign ? y.not() : y; var xDigit = 0, yDigit = 0; var xDivMod = null, yDivMod = null; var result = []; while (!xRem.isZero() || !yRem.isZero()) {
xDivMod = divModAny(xRem, highestPower2);
xDigit = xDivMod[1].toJSNumber();
if (xSign) {
xDigit = highestPower2 - 1 - xDigit;
}
yDivMod = divModAny(yRem, highestPower2);
yDigit = yDivMod[1].toJSNumber();
if (ySign) {
yDigit = highestPower2 - 1 - yDigit;
}
xRem = xDivMod[0];
yRem = yDivMod[0];
result.push(fn(xDigit, yDigit));
} var sum = fn(xSign ? 1 : 0, ySign ? 1 : 0) !== 0 ? bigInt(-1) : bigInt(0); for (var i = result.length - 1; i >= 0; i -= 1) {
sum = sum.multiply(highestPower2).add(bigInt(result[i]));
} return sum; }
BigInteger.prototype.not = function () { return this.negate().prev(); };
NativeBigInt.prototype.not = SmallInteger.prototype.not = BigInteger.prototype.not;
BigInteger.prototype.and = function (n) { return bitwise(this, n, function (a, b) { return a & b; }); };
NativeBigInt.prototype.and = SmallInteger.prototype.and = BigInteger.prototype.and;
BigInteger.prototype.or = function (n) { return bitwise(this, n, function (a, b) { return a | b; }); };
NativeBigInt.prototype.or = SmallInteger.prototype.or = BigInteger.prototype.or;
BigInteger.prototype.xor = function (n) { return bitwise(this, n, function (a, b) { return a ^ b; }); };
NativeBigInt.prototype.xor = SmallInteger.prototype.xor = BigInteger.prototype.xor;
var LOBMASK_I = 1 << 30, LOBMASK_BI = (BASE & -BASE) * (BASE & -BASE) | LOBMASK_I;
function roughLOB(n) { var v = n.value, x = typeof v === "number" ? v | LOBMASK_I : typeof v === "bigint" ? v | BigInt(LOBMASK_I) : v[0] + v[1] * BASE | LOBMASK_BI; return x & -x; }
function integerLogarithm(value, base) { if (base.compareTo(value) <= 0) {
var tmp = integerLogarithm(value, base.square(base));
var p = tmp.p;
var e = tmp.e;
var t = p.multiply(base);
return t.compareTo(value) <= 0 ? { p: t, e: e * 2 + 1 } : { p: p, e: e * 2 };
} return { p: bigInt(1), e: 0 }; }
BigInteger.prototype.bitLength = function () { var n = this; if (n.compareTo(bigInt(0)) < 0) {
n = n.negate().subtract(bigInt(1));
} if (n.compareTo(bigInt(0)) === 0) {
return bigInt(0);
} return bigInt(integerLogarithm(n, bigInt(2)).e).add(bigInt(1)); };
NativeBigInt.prototype.bitLength = SmallInteger.prototype.bitLength = BigInteger.prototype.bitLength;
function max(a, b) { a = parseValue(a); b = parseValue(b); return a.greater(b) ? a : b; }
function min(a, b) { a = parseValue(a); b = parseValue(b); return a.lesser(b) ? a : b; }
function gcd(a, b) { a = parseValue(a).abs(); b = parseValue(b).abs(); if (a.equals(b))
return a; if (a.isZero())
return b; if (b.isZero())
return a; var c = Integer[1], d, t; while (a.isEven() && b.isEven()) {
d = min(roughLOB(a), roughLOB(b));
a = a.divide(d);
b = b.divide(d);
c = c.multiply(d);
} while (a.isEven()) {
a = a.divide(roughLOB(a));
} do {
while (b.isEven()) {
b = b.divide(roughLOB(b));
}
if (a.greater(b)) {
t = b;
b = a;
a = t;
}
b = b.subtract(a);
} while (!b.isZero()); return c.isUnit() ? a : a.multiply(c); }
function lcm(a, b) { a = parseValue(a).abs(); b = parseValue(b).abs(); return a.divide(gcd(a, b)).multiply(b); }
function randBetween(a, b) { a = parseValue(a); b = parseValue(b); var low = min(a, b), high = max(a, b); var range = high.subtract(low).add(1); if (range.isSmall)
return low.add(Math.floor(Math.random() * range)); var digits = toBase(range, BASE).value; var result = [], restricted = true; for (var i = 0; i < digits.length; i++) {
var top = restricted ? digits[i] : BASE;
var digit = truncate(Math.random() * top);
result.push(digit);
if (digit < top)
restricted = false;
} return low.add(Integer.fromArray(result, BASE, false)); }
var parseBase = function (text, base, alphabet, caseSensitive) { alphabet = alphabet || DEFAULT_ALPHABET; text = String(text); if (!caseSensitive) {
text = text.toLowerCase();
alphabet = alphabet.toLowerCase();
} var length = text.length; var i; var absBase = Math.abs(base); var alphabetValues = {}; for (i = 0; i < alphabet.length; i++) {
alphabetValues[alphabet[i]] = i;
} for (i = 0; i < length; i++) {
var c = text[i];
if (c === "-")
continue;
if (c in alphabetValues) {
if (alphabetValues[c] >= absBase) {
if (c === "1" && absBase === 1)
continue;
throw new Error(c + " is not a valid digit in base " + base + ".");
}
}
} base = parseValue(base); var digits = []; var isNegative = text[0] === "-"; for (i = isNegative ? 1 : 0; i < text.length; i++) {
var c = text[i];
if (c in alphabetValues)
digits.push(parseValue(alphabetValues[c]));
else if (c === "<") {
var start = i;
do {
i++;
} while (text[i] !== ">" && i < text.length);
digits.push(parseValue(text.slice(start + 1, i)));
}
else
throw new Error(c + " is not a valid character");
} return parseBaseFromArray(digits, base, isNegative); };
function parseBaseFromArray(digits, base, isNegative) { var val = Integer[0], pow = Integer[1], i; for (i = digits.length - 1; i >= 0; i--) {
val = val.add(digits[i].times(pow));
pow = pow.times(base);
} return isNegative ? val.negate() : val; }
function stringify(digit, alphabet) { alphabet = alphabet || DEFAULT_ALPHABET; if (digit < alphabet.length) {
return alphabet[digit];
} return "<" + digit + ">"; }
function toBase(n, base) { base = bigInt(base); if (base.isZero()) {
if (n.isZero())
return { value: [0], isNegative: false };
throw new Error("Cannot convert nonzero numbers to base 0.");
} if (base.equals(-1)) {
if (n.isZero())
return { value: [0], isNegative: false };
if (n.isNegative())
return { value: [].concat.apply([], Array.apply(null, Array(-n.toJSNumber())).map(Array.prototype.valueOf, [1, 0])), isNegative: false };
var arr = Array.apply(null, Array(n.toJSNumber() - 1)).map(Array.prototype.valueOf, [0, 1]);
arr.unshift([1]);
return { value: [].concat.apply([], arr), isNegative: false };
} var neg = false; if (n.isNegative() && base.isPositive()) {
neg = true;
n = n.abs();
} if (base.isUnit()) {
if (n.isZero())
return { value: [0], isNegative: false };
return { value: Array.apply(null, Array(n.toJSNumber())).map(Number.prototype.valueOf, 1), isNegative: neg };
} var out = []; var left = n, divmod; while (left.isNegative() || left.compareAbs(base) >= 0) {
divmod = left.divmod(base);
left = divmod.quotient;
var digit = divmod.remainder;
if (digit.isNegative()) {
digit = base.minus(digit).abs();
left = left.next();
}
out.push(digit.toJSNumber());
} out.push(left.toJSNumber()); return { value: out.reverse(), isNegative: neg }; }
function toBaseString(n, base, alphabet) { var arr = toBase(n, base); return (arr.isNegative ? "-" : "") + arr.value.map(function (x) { return stringify(x, alphabet); }).join(""); }
BigInteger.prototype.toArray = function (radix) { return toBase(this, radix); };
SmallInteger.prototype.toArray = function (radix) { return toBase(this, radix); };
NativeBigInt.prototype.toArray = function (radix) { return toBase(this, radix); };
BigInteger.prototype.toString = function (radix, alphabet) { if (radix === undefined)
radix = 10; if (radix !== 10)
return toBaseString(this, radix, alphabet); var v = this.value, l = v.length, str = String(v[--l]), zeros = "0000000", digit; while (--l >= 0) {
digit = String(v[l]);
str += zeros.slice(digit.length) + digit;
} var sign = this.sign ? "-" : ""; return sign + str; };
SmallInteger.prototype.toString = function (radix, alphabet) { if (radix === undefined)
radix = 10; if (radix != 10)
return toBaseString(this, radix, alphabet); return String(this.value); };
NativeBigInt.prototype.toString = SmallInteger.prototype.toString;
NativeBigInt.prototype.toJSON = BigInteger.prototype.toJSON = SmallInteger.prototype.toJSON = function () { return this.toString(); };
BigInteger.prototype.valueOf = function () { return parseInt(this.toString(), 10); };
BigInteger.prototype.toJSNumber = BigInteger.prototype.valueOf;
SmallInteger.prototype.valueOf = function () { return this.value; };
SmallInteger.prototype.toJSNumber = SmallInteger.prototype.valueOf;
NativeBigInt.prototype.valueOf = NativeBigInt.prototype.toJSNumber = function () { return parseInt(this.toString(), 10); };
function parseStringValue(v) { if (isPrecise(+v)) {
var x = +v;
if (x === truncate(x))
return supportsNativeBigInt ? new NativeBigInt(BigInt(x)) : new SmallInteger(x);
throw new Error("Invalid integer: " + v);
} var sign = v[0] === "-"; if (sign)
v = v.slice(1); var split = v.split(/e/i); if (split.length > 2)
throw new Error("Invalid integer: " + split.join("e")); if (split.length === 2) {
var exp = split[1];
if (exp[0] === "+")
exp = exp.slice(1);
exp = +exp;
if (exp !== truncate(exp) || !isPrecise(exp))
throw new Error("Invalid integer: " + exp + " is not a valid exponent.");
var text = split[0];
var decimalPlace = text.indexOf(".");
if (decimalPlace >= 0) {
exp -= text.length - decimalPlace - 1;
text = text.slice(0, decimalPlace) + text.slice(decimalPlace + 1);
}
if (exp < 0)
throw new Error("Cannot include negative exponent part for integers");
text += new Array(exp + 1).join("0");
v = text;
} var isValid = /^([0-9][0-9]*)$/.test(v); if (!isValid)
throw new Error("Invalid integer: " + v); if (supportsNativeBigInt) {
return new NativeBigInt(BigInt(sign ? "-" + v : v));
} var r = [], max = v.length, l = LOG_BASE, min = max - l; while (max > 0) {
r.push(+v.slice(min, max));
min -= l;
if (min < 0)
min = 0;
max -= l;
} trim(r); return new BigInteger(r, sign); }
function parseNumberValue(v) { if (supportsNativeBigInt) {
return new NativeBigInt(BigInt(v));
} if (isPrecise(v)) {
if (v !== truncate(v))
throw new Error(v + " is not an integer.");
return new SmallInteger(v);
} return parseStringValue(v.toString()); }
function parseValue(v) { if (typeof v === "number") {
return parseNumberValue(v);
} if (typeof v === "string") {
return parseStringValue(v);
} if (typeof v === "bigint") {
return new NativeBigInt(v);
} return v; }
for (var i = 0; i < 1e3; i++) {
Integer[i] = parseValue(i);
if (i > 0)
Integer[-i] = parseValue(-i);
}
Integer.one = Integer[1];
Integer.zero = Integer[0];
Integer.minusOne = Integer[-1];
Integer.max = max;
Integer.min = min;
Integer.gcd = gcd;
Integer.lcm = lcm;
Integer.isInstance = function (x) { return x instanceof BigInteger || x instanceof SmallInteger || x instanceof NativeBigInt; };
Integer.randBetween = randBetween;
Integer.fromArray = function (digits, base, isNegative) { return parseBaseFromArray(digits.map(parseValue), parseValue(base || 10), isNegative); };
return Integer;
}();
if (typeof module !== "undefined" && module.hasOwnProperty("exports")) {
module.exports = bigInt;
}
if (typeof define === "function" && define.amd) {
define("big-integer", [], function () { return bigInt; });
}

55
dist/lib/otp.js vendored Normal file
View File

@@ -0,0 +1,55 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const base32_1 = __importDefault(require("./base32"));
const crypto_1 = require("crypto");
class OTP {
constructor(seed = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz!@#$-') {
this.seed = seed;
}
validateHotp(token, secret, counter) {
const counterInt = parseInt(counter, 10) || 0;
if (!secret || !token || token.length !== 6 || isNaN(parseInt(token, 10)))
return false;
return this._computeHotp(secret, counterInt) === token;
}
validateTotp(token, secret) {
return this.validateHotp(token, secret, Math.floor(Date.now() / 30 / 1000));
}
generateKey(name = 'Secret Key', issuer = null, hotp = false) {
const bytes = crypto_1.randomBytes(32);
const string = Array(32)
.fill(i => this.seed[Math.floor(bytes[i] / 255.0 * (this.seed.length - 1))])
.map((f, i) => f(i))
.join('');
const key = {
raw: string,
base32: base32_1.default.encode(string)
};
return Object.defineProperty(key, 'url', {
value: 'google_url',
writable: false,
get: () => `otpauth://${hotp ? 'h' : 't'}otp/${name}?secret=${key.base32}${issuer ? `&issuer=${issuer}` : ''}`
});
}
_computeHotp(secret, counter) {
secret = base32_1.default.decode(secret);
let tmp = counter;
const chunks = Buffer.alloc(8);
for (let i = 0; i < 8; i++) {
chunks[7 - i] = tmp & 0xff;
tmp = tmp >> 8;
}
const digest = crypto_1.createHmac('sha1', secret).update(chunks).digest();
const offset = digest[digest.length - 1] & 0xf;
let code = (digest[offset] & 0x7f) << 24 |
(digest[offset + 1] & 0xff) << 16 |
(digest[offset + 2] & 0xff) << 8 |
(digest[offset + 3] & 0xff);
code = new Array(7).join('0') + code.toString(10);
return code.substr(-6);
}
}
exports.default = OTP;

8
dist/lib/snowflakey.js vendored Normal file
View File

@@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Master = require('./Snowflake/Master').default;
exports.Worker = require('./Snowflake/Worker').default;
exports.lookup = (flake, epoch) => {
return new Date((flake / 4194304) + epoch);
};
exports.Token = require('./Token/main').default;

2
dist/lib/types.js vendored Normal file
View File

@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

8
dist/lib/util.js vendored Normal file
View File

@@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.sleep = (duration = 1) => {
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, (duration * 1000));
};
exports.getBits = (bits) => {
return (2 ** bits) - 1;
};

39
dist/tests/main.test.js vendored Normal file
View File

@@ -0,0 +1,39 @@
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const Snowflake = __importStar(require("../lib/snowflakey"));
const master = new Snowflake.Master();
const worker = new Snowflake.Worker({
name: 'starling',
epoch: 1420070400000,
workerId: process.env.CLUSTER_ID || 31,
processId: process.pid || undefined,
workerBits: 8,
processBits: 0,
incrementBits: 14
});
master.addWorkers(worker);
const flake = worker.generate();
const epoch = 1420070400000;
console.log('----------[ Worker ]----------');
console.log(`Created snowflake: ${flake}`);
console.log(`Creation date : ${Snowflake.lookup(flake, worker.options.epoch)}`);
console.log(`Deconstructed : ${worker.deconstruct(flake).timestamp.valueOf()}`);
console.log('----------[ Master ]----------');
master.on('newSnowflake', (data) => {
console.log(`created snowflake: ${data.snowflake} by Worker ${data.worker.options.name || data.worker.options.workerId}`);
console.log(`Creation date : ${Snowflake.lookup(flake, data.worker.options.epoch)}`);
data.worker.deconstruct(data.snowflake);
});
master.on('deconstructedFlake', (data) => {
console.log(`Deconstructed : ${data.timestamp.valueOf()} by Worker ${data.worker.options.name || data.worker.options.workerId}`);
});
worker.generate();
master.removeWorkers(worker.options.name);
console.log(master.listWorkers());

39
dist/tests/snowflake.test.js vendored Normal file
View File

@@ -0,0 +1,39 @@
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const Snowflake = __importStar(require("../lib/snowflakey"));
const master = new Snowflake.Master();
const worker = new Snowflake.Worker({
name: 'starling',
epoch: 1420070400000,
workerId: process.env.CLUSTER_ID || 31,
processId: process.pid || undefined,
workerBits: 8,
processBits: 0,
incrementBits: 14
});
master.addWorkers(worker);
const flake = worker.generate();
console.log('----------[ Worker ]----------');
console.log(`Created snowflake: ${flake}`);
console.log(`Creation date : ${Snowflake.lookup(flake, worker.options.epoch).toLocaleString()}`);
console.log(`Deconstructed : ${worker.deconstruct(flake).timestamp.valueOf()}`);
console.log('----------[ Master ]----------');
master.on('newSnowflake', (data) => {
console.log(`created snowflake: ${data.snowflake.toString()} by Worker ${data.worker.options.name || data.worker.options.workerId}`);
console.log(`Creation date : ${Snowflake.lookup(flake, data.worker.options.epoch).toLocaleString()}`);
data.worker.deconstruct(data.snowflake);
});
master.on('deconstructedFlake', (data) => {
console.log(`Deconstructed : ${data.timestamp.valueOf()} by Worker ${data.worker.options.name || data.worker.options.workerId}`);
});
worker.generate();
console.log(`Workers before : ${master.listWorkers().length}`);
master.removeWorkers(worker.options.name);
console.log(`Workers after : ${master.listWorkers().length}`);

6
dist/tests/token.test.js vendored Normal file
View File

@@ -0,0 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const snowflakey_1 = require("../lib/snowflakey");
const Generator = new snowflakey_1.Token({ secret: 'VerySecretSecret1' });
const token = Generator.generate('107130754189766656');
console.log(token);

104
index.d.ts vendored
View File

@@ -5,64 +5,90 @@ declare module 'snowflakey' {
import { EventEmitter } from 'events';
export type Snowflake = number;
export function lookup(flake: number, epoch: number);
export function lookup(flake: number, epoch: number): Date;
export class Token {
public secret: string;
public EPOCH: number;
public VERSION: number;
public tokenTime: number;
private _otp: any;
public constructor(options: TokenConfig);
public generate(ID: string): string;
public update(token: string, mfa: string, secret: string, counter: any): string | null
public validate(token: string, fetcher: any): boolean;
private _computeHmac(string: string): string;
}
export class Master extends EventEmitter {
public workers: SnowflakeWorker[];
constructor();
public workers: Worker[];
public refresh(): void;
public listWorkers(): SnowflakeWorker[];
public addWorkers(...workers: any[]): void;
public listWorkers(): Worker[];
public addWorkers(...workers: Worker[]): void;
public removeWorkers(...workers: string[] | number[]): { removed: number };
public on(event: 'newSnowflake', listener: (data: NewSnowflake) => void): this;
public on(event: 'deconstructedFlake', listener: (data: DeconstructedSnowflake) => void): this;
}
export class Worker extends EventEmitter {
public options: SnowflakeConfig;
private _mutable: SnowflakeMutable;
public options: SnowflakeConfig;
constructor(options: SnowflakeConfig);
private _lock(): void;
private _unlock(): void;
public generate(): Snowflake;
public deconstruct(flake: Snowflake): DeconstructedSnowflake;
public deconstruct(flake: Snowflake, epoch?: number): DeconstructedSnowflake;
public on(event: 'newSnowflake', listener: (data: NewSnowflake) => void): this;
public on(event: 'deconstructedFlake', listener: (data: DeconstructedSnowflake) => void): this;
private _lock(): Promise<any> | void;
private _unlock(): void;
private _generate(): Snowflake;
private _generateAsync(): Snowflake;
}
export interface DeconstructedSnowflake {
workerId: number,
timestamp: number,
processId: number,
increment: number
export interface TokenConfig {
seed?: string;
secret: string;
epoch?: number;
version?: number;
}
export interface DeconstructedSnowflake {
method: 'sync' | 'async';
worker: Worker;
workerId: number;
timestamp: number;
processId: number;
increment: number;
}
export interface NewSnowflake {
method: 'sync' | 'async';
worker: Worker;
snowflake: Snowflake;
}
export interface SnowflakeConfig {
name?: string;
async?: boolean;
epoch: number;
workerId?: any,
processId?: number,
stringify?: boolean,
workerBits: number,
processBits: number,
name?: string;
async?: boolean;
stringify?: boolean,
workerId?: any,
epoch: number;
processId?: number,
workerBits: number,
processBits: number,
incrementBits: number
}
export interface SnowflakeMutable {
locks: any;
locked: boolean;
increment: any;
locks: [];
locked: boolean;
increment: number;
lastTimestamp: number;
}
export interface SnowflakeWorker {
options: SnowflakeConfig;
workerId: number;
_mutable: SnowflakeMutable;
processId: number;
_maxIncrement: number;
_lock(): void;
_unlock(): void;
generate(): Snowflake;
_generate(): Snowflake;
_generateAsync(): Snowflake;
}
}
}

View File

@@ -1,8 +1,8 @@
import { EventEmitter } from 'events';
import { SnowflakeWorker } from './types';
import { SnowflakeWorker } from '../types';
export default class SnowflakeMaster extends EventEmitter {
public workers: any[]
public workers: any[];
constructor() {
super();
@@ -11,9 +11,7 @@ export default class SnowflakeMaster extends EventEmitter {
}
addWorkers(...workers: SnowflakeWorker[]): void {
for (const worker of workers) {
this.workers.push(worker);
}
for (const worker of workers) this.workers.push(worker);
return this.refresh();
}

View File

@@ -1,37 +1,37 @@
import big from './bigInt';
import { EventEmitter } from 'events';
import { sleep, getBits } from './util'
import { Snowflake, SnowflakeConfig, SnowflakeMutable } from './types';
import { Snowflake, SnowflakeConfig, SnowflakeMutable } from '../types';
export default class SnowflakeWorker extends EventEmitter {
public options: SnowflakeConfig;
private _mutable: SnowflakeMutable;
private _maxIncrement: Number;
public workerId: number;
public processId: number;
public workerId: number;
public processId: number;
public options: SnowflakeConfig;
private _mutable: SnowflakeMutable;
private _maxIncrement: number;
constructor(options: SnowflakeConfig) {
super();
// The default options for the generator
this.setMaxListeners(100);
this.options = {
name: undefined,
async: false,
epoch: null,
workerId: 0,
processId: 0,
stringify: true,
workerBits: 5,
processBits: 5,
name: undefined,
async: false,
stringify: true,
workerId: 0,
processId: 0,
workerBits: 5,
processBits: 5,
incrementBits: 12,
epoch: null,
...options
};
// an object containing mutable (unfrozen) properties
this._mutable = {
locks: [],
locked: false,
increment: big.zero.subtract(1),
locks: [],
locked: false,
increment: big.zero.subtract(1),
lastTimestamp: Date.now()
};
@@ -53,7 +53,6 @@ export default class SnowflakeWorker extends EventEmitter {
// freeze immutable objects to prevent tampering
Object.freeze(this.options);
// Object.freeze(this);
}
get increment(): number {
@@ -79,27 +78,27 @@ export default class SnowflakeWorker extends EventEmitter {
this.emit('newSnowflake', {
worker: this,
method: 'sync',
snowflake: flake.toString(),
snowflake: flake,
});
if (this.options.stringify) flake = flake.toString();
return flake;
}
_lock() {
private _lock(): Promise<boolean> | void {
if (this._mutable.locked) return new Promise(res => this._mutable.locks.push(res));
else this._mutable.locked = true;
}
_unlock(): void {
private _unlock(): void {
if (this._mutable.locks.length > 0) this._mutable.locks.shift()();
else this._mutable.locked = false;
}
async _generateAsync(): Promise<Snowflake> {
let lock = this._lock();
private async _generateAsync(): Promise<Snowflake> {
let lock: any = this._lock();
if (lock) await lock;
let now = Date.now();
let now: number = Date.now();
// check if increment should be reset
if (this._mutable.lastTimestamp !== now) {
// last timestamp didnt match, reset increment
@@ -123,18 +122,18 @@ export default class SnowflakeWorker extends EventEmitter {
this._unlock();
this.emit('newSnowflake', {
worker: this,
method: 'async',
snowflake: flake.toString(),
method: 'sync',
snowflake: flake,
});
return flake;
}
deconstruct(snowflake: Snowflake): object {
deconstruct(snowflake: Snowflake, epoch: number = this.options.epoch): object {
// turn snowflake into a bigint
let flake = big(snowflake);
let flake: any = big(snowflake);
// shift right, and add epoch to obtain timestamp
let timestamp = flake.shiftRight(22).add(this.options.epoch);
let timestamp = flake.shiftRight(22).add(epoch);
//obtain workerId
let wBitShift = this.options.incrementBits + this.options.processBits;
@@ -153,4 +152,4 @@ export default class SnowflakeWorker extends EventEmitter {
});
return { timestamp, workerId, processId, increment };
}
};
};

67
lib/Token/base32.ts Normal file
View File

@@ -0,0 +1,67 @@
export default class Base32 {
static charmap: any = null;
static alphabet: string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
static encode(data: any[]): string {
let encoded: string = '';
let shift: number = 3;
let carry: number = 0;
let symbol: number;
let byte: number;
for (let i = 0; i < data.length; i++) {
byte = data[i];
symbol = carry | (byte >> shift);
encoded += Base32.alphabet[symbol & 0x1f];
if (shift > 5) {
shift -= 5;
symbol = byte >> shift;
encoded += Base32.alphabet[symbol & 0x1f];
}
shift = 5 - shift;
carry = byte << shift;
shift = 8 - shift;
}
if (shift !== 3) encoded += Base32.alphabet[carry & 0x1f];
return encoded;
}
static decode(data: string): Buffer | void {
Base32._charmap();
let shift: number = 8;
let carry: number = 0;
const chunks: number[] = [];
for (const char of data.toUpperCase().split('')) {
if (char === '') return;
const symbol: number = Base32.charmap[char] & 0xff;
shift -= 5;
if (shift > 0) carry |= symbol << shift;
else if (shift < 0) {
chunks.push(carry | (symbol >> -shift));
shift += 8;
carry = (symbol << shift) & 0xff;
} else {
chunks.push(carry | symbol);
shift = 8;
carry = 0;
}
}
if (shift !== 8 && carry !== 0) chunks.push(carry);
return Buffer.from(chunks);
}
private static _charmap() {
if (!Base32.charmap) {
const mappings: object = { 0: 14, 1: 8 };
const alphabet: string[] = Base32.alphabet.split('');
for (const i in alphabet) if (!(alphabet[i] in mappings)) mappings[alphabet[i]] = i;
Base32.charmap = mappings;
}
}
}

62
lib/Token/main.ts Normal file
View File

@@ -0,0 +1,62 @@
import { createHmac } from 'crypto'
import { TokenConfig } from '../types'
import OTP from './otp'
export default class TokenGenerator {
public EPOCH: number;
public secret: string;
public VERSION: number;
private _otp: any;
constructor(options: TokenConfig) {
this.EPOCH = options.epoch || 1546300800000;
this.secret = options.secret
this.VERSION = options.version || 1;
this._otp = new OTP(options.seed || '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz!@#$-');
}
generate(ID: string): string {
const parts: string[] = [
Buffer.from(ID).toString('base64'),
Buffer.from(this.tokenTime.toString()).toString('base64')
];
return `${parts.join('.').replace(/=/g, '')}.${this._computeHmac(parts.join('.').replace(/=/g, ''))}`;
}
upgrade(token: string, mfa: string, secret: string, counter: any = -1): string {
if (!token.startsWith('mfa.') &&
((counter === -1 && this._otp.validateTotp(mfa, secret)) ||
(counter !== -1 && this._otp.validateHotp(mfa, secret, counter)))) {
const parts: string[] = token.split('.');
return `mfa.${parts[0]}.${parts[1]}.${this._computeHmac(`mfa.${parts[0]}.${parts[1]}`)}`;
}
return null;
}
validate(token: string, fetcher: any): boolean {
const isMfa: boolean = token.startsWith('mfa.');
const partitions: string[] = token.replace(/^mfa\./, '').split('.');
if (partitions.length !== 3) return false;
const signatureStr: string = `${isMfa ? 'mfa.' : ''}${partitions[0]}.${partitions[1]}`;
if (partitions[2] !== this._computeHmac(signatureStr)) return false;
const ID: string = Buffer.from(partitions[0], 'base64').toString('utf8');
const time: string = Buffer.from(partitions[1], 'base64').toString('utf8');
const accountDetails: any = fetcher(ID);
return time > accountDetails.tokensValidSince && isMfa === accountDetails.hasMfa;
}
get tokenTime(): number {
return Math.floor((Date.now() - this.EPOCH) / 1000);
}
private _computeHmac(string: string): string {
return createHmac('sha256', this.secret).update(`TTF.${this.VERSION}.${string}`).digest('base64').replace(/=/g, '');
}
}

61
lib/Token/otp.ts Normal file
View File

@@ -0,0 +1,61 @@
import Base32 from './base32'
import { createHmac, randomBytes } from 'crypto'
export default class OTP {
public seed: string;
constructor(seed: string = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz!@#$-') {
this.seed = seed;
}
validateHotp(token: string, secret: any, counter: any): boolean {
const counterInt: number = parseInt(counter, 10) || 0;
if (!secret || !token || token.length !== 6 || isNaN(parseInt(token, 10))) return false;
return this._computeHotp(secret, counterInt) === token;
}
validateTotp(token: string, secret: string): boolean {
return this.validateHotp(token, secret, Math.floor(Date.now() / 30 / 1000));
}
generateKey(name: string = 'Secret Key', issuer: string = null, hotp: boolean = false): object {
const bytes: any = randomBytes(32);
const string: string[] = Array(32)
.fill(i => this.seed[Math.floor(bytes[i] / 255.0 * (this.seed.length - 1))])
.map((f, i) => f(i))
const key = {
raw: string.join(''),
base32: Base32.encode(string)
}
return Object.defineProperty(key, 'url', {
value: 'google_url',
writable: false,
get: () => `otpauth://${hotp ? 'h' : 't'}otp/${name}?secret=${key.base32}${issuer ? `&issuer=${issuer}` : ''}`
});
}
private _computeHotp(secret: any, counter: number): string {
secret = Base32.decode(secret);
let tmp: number = counter;
const chunks: Buffer = Buffer.alloc(8);
for (let i = 0; i < 8; i++) {
chunks[7 - i] = tmp & 0xff;
tmp = tmp >> 8;
}
const digest: Buffer = createHmac('sha1', secret).update(chunks).digest();
const offset: number = digest[digest.length - 1] & 0xf;
let code: number | string | number[] = (digest[offset] & 0x7f) << 24 |
(digest[offset + 1] & 0xff) << 16 |
(digest[offset + 2] & 0xff) << 8 |
(digest[offset + 3] & 0xff);
code = new Array(7).join('0') + code.toString(10);
return code.substr(-6);
}
}

View File

@@ -1,6 +1,7 @@
export const Master = require('./Master').default;
export const Worker = require('./Worker').default;
export const lookup = (flake: number, epoch: number): string => {
return new Date((flake / 4194304) + epoch).toLocaleString();
export const Master = require('./Snowflake/Master').default;
export const Worker = require('./Snowflake/Worker').default;
export const lookup = (flake: number, epoch: number): Date => {
return new Date((flake / 4194304) + epoch);
};
export const Token = require('./Token/main').default;

View File

@@ -1,3 +1,10 @@
export interface TokenConfig {
seed?: string;
secret: string;
epoch?: number;
version?: number;
}
export interface SnowflakeConfig {
name?: string;
async?: boolean;
@@ -30,4 +37,4 @@ export interface SnowflakeWorker {
generate(): Snowflake;
_generate(): Snowflake;
_generateAsync(): Snowflake;
}
}

View File

@@ -1,7 +1,7 @@
{
"name": "snowflakey",
"version": "0.1.1",
"description": "❄️ Fast and easy snowflake generation and lookup",
"version": "0.2.0",
"description": "❄️ Fast and easy snowflake generation and lookup and token generation",
"author": "Wessel \"wesselgame\" T <discord@go2it.eu>",
"main": "dist/lib/snowflakey.js",
"types": "index.d.ts",
@@ -27,12 +27,15 @@
"lightweight"
],
"scripts": {
"test": "cd ./dist/tests && node main.test.js",
"test:snowflake": "cd ./dist/tests && node snowflake.test.js",
"test:token": "cd ./dist/tests && node token.test.js",
"compile": "tsc"
},
"devDependencies": {
"@types/node": "^12.6.8",
"@typescript-eslint/parser": "^1.13.0"
"@typescript-eslint/parser": "^1.13.0",
"eslint": "^6.1.0",
"typescript": "^3.5.3"
},
"dependencies": {}
}

View File

@@ -16,17 +16,16 @@ master.addWorkers(worker);
// Using the worker directly
const flake = worker.generate();
const epoch = 1420070400000;
console.log('----------[ Worker ]----------')
console.log(`Created snowflake: ${flake}`);
console.log(`Creation date : ${Snowflake.lookup(flake, worker.options.epoch)}`);
console.log(`Creation date : ${Snowflake.lookup(flake, worker.options.epoch).toLocaleString()}`);
console.log(`Deconstructed : ${worker.deconstruct(flake).timestamp.valueOf()}`);
// Using the master to get events
console.log('----------[ Master ]----------')
master.on('newSnowflake', (data) => {
console.log(`created snowflake: ${data.snowflake} by Worker ${data.worker.options.name || data.worker.options.workerId}`)
console.log(`Creation date : ${Snowflake.lookup(flake, data.worker.options.epoch)}`);
console.log(`created snowflake: ${data.snowflake.toString()} by Worker ${data.worker.options.name || data.worker.options.workerId}`)
console.log(`Creation date : ${Snowflake.lookup(flake, data.worker.options.epoch).toLocaleString()}`);
data.worker.deconstruct(data.snowflake);
});
@@ -36,5 +35,6 @@ master.on('deconstructedFlake', (data) => {
worker.generate();
console.log(`Workers before : ${master.listWorkers().length}`);
master.removeWorkers(worker.options.name);
console.log(master.listWorkers())
console.log(`Workers after : ${master.listWorkers().length}`);

6
tests/token.test.ts Normal file
View File

@@ -0,0 +1,6 @@
import { Token } from '../lib/snowflakey';
const Generator = new Token({ secret: 'VerySecretSecret1' });
const token = Generator.generate('107130754189766656');
console.log(token);

View File

@@ -20,4 +20,4 @@
},
"include": [ "lib/**/*", "tests/**/*" ],
"exclude": [ "node_modules" ]
}
}

783
yarn.lock
View File

@@ -2,6 +2,22 @@
# yarn lockfile v1
"@babel/code-frame@^7.0.0":
version "7.5.5"
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.5.5.tgz#bc0782f6d69f7b7d49531219699b988f669a8f9d"
integrity sha512-27d4lZoomVyo51VegxI20xZPuSHusqbQag/ztrBC7wegWoQ1nLREPVSKSW8byhTlzTKyNE4ifaTA6lCp7JjpFw==
dependencies:
"@babel/highlight" "^7.0.0"
"@babel/highlight@^7.0.0":
version "7.5.0"
resolved "https://registry.yarnpkg.com/@babel/highlight/-/highlight-7.5.0.tgz#56d11312bd9248fa619591d02472be6e8cb32540"
integrity sha512-7dV4eu9gBxoM0dAnj/BCFDW9LFU0zvTrkq0ugM7pnHEgguOEeOz1so2ZghEdzviYzQEED0r4EAgpsBChKy1TRQ==
dependencies:
chalk "^2.0.0"
esutils "^2.0.2"
js-tokens "^4.0.0"
"@types/eslint-visitor-keys@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@types/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz#1ee30d79544ca84d68d4b3cdb0af4f205663dd2d"
@@ -44,6 +60,161 @@
lodash.unescape "4.0.1"
semver "5.5.0"
acorn-jsx@^5.0.0:
version "5.0.1"
resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-5.0.1.tgz#32a064fd925429216a09b141102bfdd185fae40e"
integrity sha512-HJ7CfNHrfJLlNTzIEUTj43LNWGkqpRLxm3YjAlcD0ACydk9XynzYsCBHxut+iqt+1aBXkx9UP/w/ZqMr13XIzg==
acorn@^6.0.7:
version "6.2.1"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-6.2.1.tgz#3ed8422d6dec09e6121cc7a843ca86a330a86b51"
integrity sha512-JD0xT5FCRDNyjDda3Lrg/IxFscp9q4tiYtxE1/nOzlKCk7hIRuYjhq1kCNkbPjMRMZuFq20HNQn1I9k8Oj0E+Q==
ajv@^6.10.0, ajv@^6.10.2:
version "6.10.2"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.10.2.tgz#d3cea04d6b017b2894ad69040fec8b623eb4bd52"
integrity sha512-TXtUUEYHuaTEbLZWIKUr5pmBuhDLy+8KYtPYdcV8qC+pOZL+NKqYwvWSRrVXHn+ZmRRAu8vJTAznH7Oag6RVRw==
dependencies:
fast-deep-equal "^2.0.1"
fast-json-stable-stringify "^2.0.0"
json-schema-traverse "^0.4.1"
uri-js "^4.2.2"
ansi-escapes@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/ansi-escapes/-/ansi-escapes-3.2.0.tgz#8780b98ff9dbf5638152d1f1fe5c1d7b4442976b"
integrity sha512-cBhpre4ma+U0T1oM5fXg7Dy1Jw7zzwv7lt/GoCpr+hDQJoYnKVPLL4dCvSEFMmQurOQvSrwT7SL/DAlhBI97RQ==
ansi-regex@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-3.0.0.tgz#ed0317c322064f79466c02966bddb605ab37d998"
integrity sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=
ansi-regex@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-4.1.0.tgz#8b9f8f08cf1acb843756a839ca8c7e3168c51997"
integrity sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==
ansi-styles@^3.2.0, ansi-styles@^3.2.1:
version "3.2.1"
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.1.tgz#41fbb20243e50b12be0f04b8dedbf07520ce841d"
integrity sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==
dependencies:
color-convert "^1.9.0"
argparse@^1.0.7:
version "1.0.10"
resolved "https://registry.yarnpkg.com/argparse/-/argparse-1.0.10.tgz#bcd6791ea5ae09725e17e5ad988134cd40b3d911"
integrity sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==
dependencies:
sprintf-js "~1.0.2"
astral-regex@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-1.0.0.tgz#6c8c3fb827dd43ee3918f27b82782ab7658a6fd9"
integrity sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg==
balanced-match@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
integrity sha1-ibTRmasr7kneFk6gK4nORi1xt2c=
brace-expansion@^1.1.7:
version "1.1.11"
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd"
integrity sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==
dependencies:
balanced-match "^1.0.0"
concat-map "0.0.1"
callsites@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/callsites/-/callsites-3.1.0.tgz#b3630abd8943432f54b3f0519238e33cd7df2f73"
integrity sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==
chalk@^2.0.0, chalk@^2.1.0, chalk@^2.4.2:
version "2.4.2"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424"
integrity sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==
dependencies:
ansi-styles "^3.2.1"
escape-string-regexp "^1.0.5"
supports-color "^5.3.0"
chardet@^0.7.0:
version "0.7.0"
resolved "https://registry.yarnpkg.com/chardet/-/chardet-0.7.0.tgz#90094849f0937f2eedc2425d0d28a9e5f0cbad9e"
integrity sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA==
cli-cursor@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/cli-cursor/-/cli-cursor-2.1.0.tgz#b35dac376479facc3e94747d41d0d0f5238ffcb5"
integrity sha1-s12sN2R5+sw+lHR9QdDQ9SOP/LU=
dependencies:
restore-cursor "^2.0.0"
cli-width@^2.0.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/cli-width/-/cli-width-2.2.0.tgz#ff19ede8a9a5e579324147b0c11f0fbcbabed639"
integrity sha1-/xnt6Kml5XkyQUewwR8PvLq+1jk=
color-convert@^1.9.0:
version "1.9.3"
resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-1.9.3.tgz#bb71850690e1f136567de629d2d5471deda4c1e8"
integrity sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==
dependencies:
color-name "1.1.3"
color-name@1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25"
integrity sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=
concat-map@0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
integrity sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=
cross-spawn@^6.0.5:
version "6.0.5"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-6.0.5.tgz#4a5ec7c64dfae22c3a14124dbacdee846d80cbc4"
integrity sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==
dependencies:
nice-try "^1.0.4"
path-key "^2.0.1"
semver "^5.5.0"
shebang-command "^1.2.0"
which "^1.2.9"
debug@^4.0.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.1.1.tgz#3b72260255109c6b589cee050f1d516139664791"
integrity sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==
dependencies:
ms "^2.1.1"
deep-is@~0.1.3:
version "0.1.3"
resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34"
integrity sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=
doctrine@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-3.0.0.tgz#addebead72a6574db783639dc87a121773973961"
integrity sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w==
dependencies:
esutils "^2.0.2"
emoji-regex@^7.0.1:
version "7.0.3"
resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-7.0.3.tgz#933a04052860c85e83c122479c4748a8e4c72156"
integrity sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA==
escape-string-regexp@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=
eslint-scope@^4.0.0:
version "4.0.3"
resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-4.0.3.tgz#ca03833310f6889a3264781aa82e63eb9cfe7848"
@@ -52,11 +223,90 @@ eslint-scope@^4.0.0:
esrecurse "^4.1.0"
estraverse "^4.1.1"
eslint-scope@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-5.0.0.tgz#e87c8887c73e8d1ec84f1ca591645c358bfc8fb9"
integrity sha512-oYrhJW7S0bxAFDvWqzvMPRm6pcgcnWc4QnofCAqRTRfQC0JcwenzGglTtsLyIuuWFfkqDG9vz67cnttSd53djw==
dependencies:
esrecurse "^4.1.0"
estraverse "^4.1.1"
eslint-utils@^1.3.1:
version "1.4.0"
resolved "https://registry.yarnpkg.com/eslint-utils/-/eslint-utils-1.4.0.tgz#e2c3c8dba768425f897cf0f9e51fe2e241485d4c"
integrity sha512-7ehnzPaP5IIEh1r1tkjuIrxqhNkzUJa9z3R92tLJdZIVdWaczEhr3EbhGtsMrVxi1KeR8qA7Off6SWc5WNQqyQ==
dependencies:
eslint-visitor-keys "^1.0.0"
eslint-visitor-keys@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz#3f3180fb2e291017716acb4c9d6d5b5c34a6a81d"
integrity sha512-qzm/XxIbxm/FHyH341ZrbnMUpe+5Bocte9xkmFMzPMjRaZMcXww+MpBptFvtU+79L362nqiLhekCxCxDPaUMBQ==
eslint@^6.1.0:
version "6.1.0"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-6.1.0.tgz#06438a4a278b1d84fb107d24eaaa35471986e646"
integrity sha512-QhrbdRD7ofuV09IuE2ySWBz0FyXCq0rriLTZXZqaWSI79CVtHVRdkFuFTViiqzZhkCgfOh9USpriuGN2gIpZDQ==
dependencies:
"@babel/code-frame" "^7.0.0"
ajv "^6.10.0"
chalk "^2.1.0"
cross-spawn "^6.0.5"
debug "^4.0.1"
doctrine "^3.0.0"
eslint-scope "^5.0.0"
eslint-utils "^1.3.1"
eslint-visitor-keys "^1.0.0"
espree "^6.0.0"
esquery "^1.0.1"
esutils "^2.0.2"
file-entry-cache "^5.0.1"
functional-red-black-tree "^1.0.1"
glob-parent "^5.0.0"
globals "^11.7.0"
ignore "^4.0.6"
import-fresh "^3.0.0"
imurmurhash "^0.1.4"
inquirer "^6.4.1"
is-glob "^4.0.0"
js-yaml "^3.13.1"
json-stable-stringify-without-jsonify "^1.0.1"
levn "^0.3.0"
lodash "^4.17.14"
minimatch "^3.0.4"
mkdirp "^0.5.1"
natural-compare "^1.4.0"
optionator "^0.8.2"
progress "^2.0.0"
regexpp "^2.0.1"
semver "^6.1.2"
strip-ansi "^5.2.0"
strip-json-comments "^3.0.1"
table "^5.2.3"
text-table "^0.2.0"
v8-compile-cache "^2.0.3"
espree@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/espree/-/espree-6.0.0.tgz#716fc1f5a245ef5b9a7fdb1d7b0d3f02322e75f6"
integrity sha512-lJvCS6YbCn3ImT3yKkPe0+tJ+mH6ljhGNjHQH9mRtiO6gjhVAOhVXW1yjnwqGwTkK3bGbye+hb00nFNmu0l/1Q==
dependencies:
acorn "^6.0.7"
acorn-jsx "^5.0.0"
eslint-visitor-keys "^1.0.0"
esprima@^4.0.0:
version "4.0.1"
resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.1.tgz#13b04cdb3e6c5d19df91ab6987a8695619b0aa71"
integrity sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==
esquery@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/esquery/-/esquery-1.0.1.tgz#406c51658b1f5991a5f9b62b1dc25b00e3e5c708"
integrity sha512-SmiyZ5zIWH9VM+SRUReLS5Q8a7GxtRdxEBVZpm98rJM7Sb+A9DVCndXfkeFUd3byderg+EbDkfnevfCwynWaNA==
dependencies:
estraverse "^4.0.0"
esrecurse@^4.1.0:
version "4.2.1"
resolved "https://registry.yarnpkg.com/esrecurse/-/esrecurse-4.2.1.tgz#007a3b9fdbc2b3bb87e4879ea19c92fdbd3942cf"
@@ -64,17 +314,548 @@ esrecurse@^4.1.0:
dependencies:
estraverse "^4.1.0"
estraverse@^4.1.0, estraverse@^4.1.1:
estraverse@^4.0.0, estraverse@^4.1.0, estraverse@^4.1.1:
version "4.2.0"
resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-4.2.0.tgz#0dee3fed31fcd469618ce7342099fc1afa0bdb13"
integrity sha1-De4/7TH81GlhjOc0IJn8GvoL2xM=
esutils@^2.0.2:
version "2.0.3"
resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.3.tgz#74d2eb4de0b8da1293711910d50775b9b710ef64"
integrity sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==
external-editor@^3.0.3:
version "3.1.0"
resolved "https://registry.yarnpkg.com/external-editor/-/external-editor-3.1.0.tgz#cb03f740befae03ea4d283caed2741a83f335495"
integrity sha512-hMQ4CX1p1izmuLYyZqLMO/qGNw10wSv9QDCPfzXfyFrOaCSSoRfqE1Kf1s5an66J5JZC62NewG+mK49jOCtQew==
dependencies:
chardet "^0.7.0"
iconv-lite "^0.4.24"
tmp "^0.0.33"
fast-deep-equal@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz#7b05218ddf9667bf7f370bf7fdb2cb15fdd0aa49"
integrity sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk=
fast-json-stable-stringify@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz#d5142c0caee6b1189f87d3a76111064f86c8bbf2"
integrity sha1-1RQsDK7msRifh9OnYREGT4bIu/I=
fast-levenshtein@~2.0.4:
version "2.0.6"
resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917"
integrity sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=
figures@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/figures/-/figures-2.0.0.tgz#3ab1a2d2a62c8bfb431a0c94cb797a2fce27c962"
integrity sha1-OrGi0qYsi/tDGgyUy3l6L84nyWI=
dependencies:
escape-string-regexp "^1.0.5"
file-entry-cache@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/file-entry-cache/-/file-entry-cache-5.0.1.tgz#ca0f6efa6dd3d561333fb14515065c2fafdf439c"
integrity sha512-bCg29ictuBaKUwwArK4ouCaqDgLZcysCFLmM/Yn/FDoqndh/9vNuQfXRDvTuXKLxfD/JtZQGKFT8MGcJBK644g==
dependencies:
flat-cache "^2.0.1"
flat-cache@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/flat-cache/-/flat-cache-2.0.1.tgz#5d296d6f04bda44a4630a301413bdbc2ec085ec0"
integrity sha512-LoQe6yDuUMDzQAEH8sgmh4Md6oZnc/7PjtwjNFSzveXqSHt6ka9fPBuso7IGf9Rz4uqnSnWiFH2B/zj24a5ReA==
dependencies:
flatted "^2.0.0"
rimraf "2.6.3"
write "1.0.3"
flatted@^2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/flatted/-/flatted-2.0.1.tgz#69e57caa8f0eacbc281d2e2cb458d46fdb449e08"
integrity sha512-a1hQMktqW9Nmqr5aktAux3JMNqaucxGcjtjWnZLHX7yyPCmlSV3M54nGYbqT8K+0GhF3NBgmJCc3ma+WOgX8Jg==
fs.realpath@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
integrity sha1-FQStJSMVjKpA20onh8sBQRmU6k8=
functional-red-black-tree@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz#1b0ab3bd553b2a0d6399d29c0e3ea0b252078327"
integrity sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=
glob-parent@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-5.0.0.tgz#1dc99f0f39b006d3e92c2c284068382f0c20e954"
integrity sha512-Z2RwiujPRGluePM6j699ktJYxmPpJKCfpGA13jz2hmFZC7gKetzrWvg5KN3+OsIFmydGyZ1AVwERCq1w/ZZwRg==
dependencies:
is-glob "^4.0.1"
glob@^7.1.3:
version "7.1.4"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.4.tgz#aa608a2f6c577ad357e1ae5a5c26d9a8d1969255"
integrity sha512-hkLPepehmnKk41pUGm3sYxoFs/umurYfYJCerbXEyFIWcAzvpipAgVkBqqT9RBKMGjnq6kMuyYwha6csxbiM1A==
dependencies:
fs.realpath "^1.0.0"
inflight "^1.0.4"
inherits "2"
minimatch "^3.0.4"
once "^1.3.0"
path-is-absolute "^1.0.0"
globals@^11.7.0:
version "11.12.0"
resolved "https://registry.yarnpkg.com/globals/-/globals-11.12.0.tgz#ab8795338868a0babd8525758018c2a7eb95c42e"
integrity sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==
has-flag@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd"
integrity sha1-tdRU3CGZriJWmfNGfloH87lVuv0=
iconv-lite@^0.4.24:
version "0.4.24"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b"
integrity sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==
dependencies:
safer-buffer ">= 2.1.2 < 3"
ignore@^4.0.6:
version "4.0.6"
resolved "https://registry.yarnpkg.com/ignore/-/ignore-4.0.6.tgz#750e3db5862087b4737ebac8207ffd1ef27b25fc"
integrity sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==
import-fresh@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/import-fresh/-/import-fresh-3.1.0.tgz#6d33fa1dcef6df930fae003446f33415af905118"
integrity sha512-PpuksHKGt8rXfWEr9m9EHIpgyyaltBy8+eF6GJM0QCAxMgxCfucMF3mjecK2QsJr0amJW7gTqh5/wht0z2UhEQ==
dependencies:
parent-module "^1.0.0"
resolve-from "^4.0.0"
imurmurhash@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea"
integrity sha1-khi5srkoojixPcT7a21XbyMUU+o=
inflight@^1.0.4:
version "1.0.6"
resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9"
integrity sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=
dependencies:
once "^1.3.0"
wrappy "1"
inherits@2:
version "2.0.4"
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c"
integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==
inquirer@^6.4.1:
version "6.5.0"
resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-6.5.0.tgz#2303317efc9a4ea7ec2e2df6f86569b734accf42"
integrity sha512-scfHejeG/lVZSpvCXpsB4j/wQNPM5JC8kiElOI0OUTwmc1RTpXr4H32/HOlQHcZiYl2z2VElwuCVDRG8vFmbnA==
dependencies:
ansi-escapes "^3.2.0"
chalk "^2.4.2"
cli-cursor "^2.1.0"
cli-width "^2.0.0"
external-editor "^3.0.3"
figures "^2.0.0"
lodash "^4.17.12"
mute-stream "0.0.7"
run-async "^2.2.0"
rxjs "^6.4.0"
string-width "^2.1.0"
strip-ansi "^5.1.0"
through "^2.3.6"
is-extglob@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/is-extglob/-/is-extglob-2.1.1.tgz#a88c02535791f02ed37c76a1b9ea9773c833f8c2"
integrity sha1-qIwCU1eR8C7TfHahueqXc8gz+MI=
is-fullwidth-code-point@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz#a3b30a5c4f199183167aaab93beefae3ddfb654f"
integrity sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=
is-glob@^4.0.0, is-glob@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-4.0.1.tgz#7567dbe9f2f5e2467bc77ab83c4a29482407a5dc"
integrity sha512-5G0tKtBTFImOqDnLB2hG6Bp2qcKEFduo4tZu9MT/H6NQv/ghhy30o55ufafxJ/LdH79LLs2Kfrn85TLKyA7BUg==
dependencies:
is-extglob "^2.1.1"
is-promise@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/is-promise/-/is-promise-2.1.0.tgz#79a2a9ece7f096e80f36d2b2f3bc16c1ff4bf3fa"
integrity sha1-eaKp7OfwlugPNtKy87wWwf9L8/o=
isexe@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"
integrity sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=
js-tokens@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==
js-yaml@^3.13.1:
version "3.13.1"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.13.1.tgz#aff151b30bfdfa8e49e05da22e7415e9dfa37847"
integrity sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==
dependencies:
argparse "^1.0.7"
esprima "^4.0.0"
json-schema-traverse@^0.4.1:
version "0.4.1"
resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz#69f6a87d9513ab8bb8fe63bdb0979c448e684660"
integrity sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==
json-stable-stringify-without-jsonify@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz#9db7b59496ad3f3cfef30a75142d2d930ad72651"
integrity sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=
levn@^0.3.0, levn@~0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/levn/-/levn-0.3.0.tgz#3b09924edf9f083c0490fdd4c0bc4421e04764ee"
integrity sha1-OwmSTt+fCDwEkP3UwLxEIeBHZO4=
dependencies:
prelude-ls "~1.1.2"
type-check "~0.3.2"
lodash.unescape@4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/lodash.unescape/-/lodash.unescape-4.0.1.tgz#bf2249886ce514cda112fae9218cdc065211fc9c"
integrity sha1-vyJJiGzlFM2hEvrpIYzcBlIR/Jw=
lodash@^4.17.12, lodash@^4.17.14:
version "4.17.15"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548"
integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==
mimic-fn@^1.0.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-1.2.0.tgz#820c86a39334640e99516928bd03fca88057d022"
integrity sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ==
minimatch@^3.0.4:
version "3.0.4"
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083"
integrity sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==
dependencies:
brace-expansion "^1.1.7"
minimist@0.0.8:
version "0.0.8"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d"
integrity sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=
mkdirp@^0.5.1:
version "0.5.1"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
integrity sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=
dependencies:
minimist "0.0.8"
ms@^2.1.1:
version "2.1.2"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"
integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==
mute-stream@0.0.7:
version "0.0.7"
resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.7.tgz#3075ce93bc21b8fab43e1bc4da7e8115ed1e7bab"
integrity sha1-MHXOk7whuPq0PhvE2n6BFe0ee6s=
natural-compare@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7"
integrity sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=
nice-try@^1.0.4:
version "1.0.5"
resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366"
integrity sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==
once@^1.3.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1"
integrity sha1-WDsap3WWHUsROsF9nFC6753Xa9E=
dependencies:
wrappy "1"
onetime@^2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/onetime/-/onetime-2.0.1.tgz#067428230fd67443b2794b22bba528b6867962d4"
integrity sha1-BnQoIw/WdEOyeUsiu6UotoZ5YtQ=
dependencies:
mimic-fn "^1.0.0"
optionator@^0.8.2:
version "0.8.2"
resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.8.2.tgz#364c5e409d3f4d6301d6c0b4c05bba50180aeb64"
integrity sha1-NkxeQJ0/TWMB1sC0wFu6UBgK62Q=
dependencies:
deep-is "~0.1.3"
fast-levenshtein "~2.0.4"
levn "~0.3.0"
prelude-ls "~1.1.2"
type-check "~0.3.2"
wordwrap "~1.0.0"
os-tmpdir@~1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/os-tmpdir/-/os-tmpdir-1.0.2.tgz#bbe67406c79aa85c5cfec766fe5734555dfa1274"
integrity sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=
parent-module@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/parent-module/-/parent-module-1.0.1.tgz#691d2709e78c79fae3a156622452d00762caaaa2"
integrity sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==
dependencies:
callsites "^3.0.0"
path-is-absolute@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f"
integrity sha1-F0uSaHNVNP+8es5r9TpanhtcX18=
path-key@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/path-key/-/path-key-2.0.1.tgz#411cadb574c5a140d3a4b1910d40d80cc9f40b40"
integrity sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=
prelude-ls@~1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"
integrity sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=
progress@^2.0.0:
version "2.0.3"
resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.3.tgz#7e8cf8d8f5b8f239c1bc68beb4eb78567d572ef8"
integrity sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==
punycode@^2.1.0:
version "2.1.1"
resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec"
integrity sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==
regexpp@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-2.0.1.tgz#8d19d31cf632482b589049f8281f93dbcba4d07f"
integrity sha512-lv0M6+TkDVniA3aD1Eg0DVpfU/booSu7Eev3TDO/mZKHBfVjgCGTV4t4buppESEYDtkArYFOxTJWv6S5C+iaNw==
resolve-from@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-4.0.0.tgz#4abcd852ad32dd7baabfe9b40e00a36db5f392e6"
integrity sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==
restore-cursor@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/restore-cursor/-/restore-cursor-2.0.0.tgz#9f7ee287f82fd326d4fd162923d62129eee0dfaf"
integrity sha1-n37ih/gv0ybU/RYpI9YhKe7g368=
dependencies:
onetime "^2.0.0"
signal-exit "^3.0.2"
rimraf@2.6.3:
version "2.6.3"
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.3.tgz#b2d104fe0d8fb27cf9e0a1cda8262dd3833c6cab"
integrity sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==
dependencies:
glob "^7.1.3"
run-async@^2.2.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/run-async/-/run-async-2.3.0.tgz#0371ab4ae0bdd720d4166d7dfda64ff7a445a6c0"
integrity sha1-A3GrSuC91yDUFm19/aZP96RFpsA=
dependencies:
is-promise "^2.1.0"
rxjs@^6.4.0:
version "6.5.2"
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.5.2.tgz#2e35ce815cd46d84d02a209fb4e5921e051dbec7"
integrity sha512-HUb7j3kvb7p7eCUHE3FqjoDsC1xfZQ4AHFWfTKSpZ+sAhhz5X1WX0ZuUqWbzB2QhSLp3DoLUG+hMdEDKqWo2Zg==
dependencies:
tslib "^1.9.0"
"safer-buffer@>= 2.1.2 < 3":
version "2.1.2"
resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a"
integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==
semver@5.5.0:
version "5.5.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.5.0.tgz#dc4bbc7a6ca9d916dee5d43516f0092b58f7b8ab"
integrity sha512-4SJ3dm0WAwWy/NVeioZh5AntkdJoWKxHxcmyP622fOkgHa4z3R0TdBJICINyaSDE6uNwVc8gZr+ZinwZAH4xIA==
semver@^5.5.0:
version "5.7.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.0.tgz#790a7cf6fea5459bac96110b29b60412dc8ff96b"
integrity sha512-Ya52jSX2u7QKghxeoFGpLwCtGlt7j0oY9DYb5apt9nPlJ42ID+ulTXESnt/qAQcoSERyZ5sl3LDIOw0nAn/5DA==
semver@^6.1.2:
version "6.3.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==
shebang-command@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-1.2.0.tgz#44aac65b695b03398968c39f363fee5deafdf1ea"
integrity sha1-RKrGW2lbAzmJaMOfNj/uXer98eo=
dependencies:
shebang-regex "^1.0.0"
shebang-regex@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-1.0.0.tgz#da42f49740c0b42db2ca9728571cb190c98efea3"
integrity sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=
signal-exit@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
integrity sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=
slice-ansi@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/slice-ansi/-/slice-ansi-2.1.0.tgz#cacd7693461a637a5788d92a7dd4fba068e81636"
integrity sha512-Qu+VC3EwYLldKa1fCxuuvULvSJOKEgk9pi8dZeCVK7TqBfUNTH4sFkk4joj8afVSfAYgJoSOetjx9QWOJ5mYoQ==
dependencies:
ansi-styles "^3.2.0"
astral-regex "^1.0.0"
is-fullwidth-code-point "^2.0.0"
sprintf-js@~1.0.2:
version "1.0.3"
resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c"
integrity sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=
string-width@^2.1.0:
version "2.1.1"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-2.1.1.tgz#ab93f27a8dc13d28cac815c462143a6d9012ae9e"
integrity sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==
dependencies:
is-fullwidth-code-point "^2.0.0"
strip-ansi "^4.0.0"
string-width@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-3.1.0.tgz#22767be21b62af1081574306f69ac51b62203961"
integrity sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==
dependencies:
emoji-regex "^7.0.1"
is-fullwidth-code-point "^2.0.0"
strip-ansi "^5.1.0"
strip-ansi@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-4.0.0.tgz#a8479022eb1ac368a871389b635262c505ee368f"
integrity sha1-qEeQIusaw2iocTibY1JixQXuNo8=
dependencies:
ansi-regex "^3.0.0"
strip-ansi@^5.1.0, strip-ansi@^5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-5.2.0.tgz#8c9a536feb6afc962bdfa5b104a5091c1ad9c0ae"
integrity sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==
dependencies:
ansi-regex "^4.1.0"
strip-json-comments@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-3.0.1.tgz#85713975a91fb87bf1b305cca77395e40d2a64a7"
integrity sha512-VTyMAUfdm047mwKl+u79WIdrZxtFtn+nBxHeb844XBQ9uMNTuTHdx2hc5RiAJYqwTj3wc/xe5HLSdJSkJ+WfZw==
supports-color@^5.3.0:
version "5.5.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.5.0.tgz#e2e69a44ac8772f78a1ec0b35b689df6530efc8f"
integrity sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==
dependencies:
has-flag "^3.0.0"
table@^5.2.3:
version "5.4.5"
resolved "https://registry.yarnpkg.com/table/-/table-5.4.5.tgz#c8f4ea2d8fee08c0027fac27b0ec0a4fe01dfa42"
integrity sha512-oGa2Hl7CQjfoaogtrOHEJroOcYILTx7BZWLGsJIlzoWmB2zmguhNfPJZsWPKYek/MgCxfco54gEi31d1uN2hFA==
dependencies:
ajv "^6.10.2"
lodash "^4.17.14"
slice-ansi "^2.1.0"
string-width "^3.0.0"
text-table@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4"
integrity sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=
through@^2.3.6:
version "2.3.8"
resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5"
integrity sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=
tmp@^0.0.33:
version "0.0.33"
resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9"
integrity sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==
dependencies:
os-tmpdir "~1.0.2"
tslib@^1.9.0:
version "1.10.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.10.0.tgz#c3c19f95973fb0a62973fb09d90d961ee43e5c8a"
integrity sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ==
type-check@~0.3.2:
version "0.3.2"
resolved "https://registry.yarnpkg.com/type-check/-/type-check-0.3.2.tgz#5884cab512cf1d355e3fb784f30804b2b520db72"
integrity sha1-WITKtRLPHTVeP7eE8wgEsrUg23I=
dependencies:
prelude-ls "~1.1.2"
typescript@^3.5.3:
version "3.5.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.5.3.tgz#c830f657f93f1ea846819e929092f5fe5983e977"
integrity sha512-ACzBtm/PhXBDId6a6sDJfroT2pOWt/oOnk4/dElG5G33ZL776N3Y6/6bKZJBFpd+b05F3Ct9qDjMeJmRWtE2/g==
uri-js@^4.2.2:
version "4.2.2"
resolved "https://registry.yarnpkg.com/uri-js/-/uri-js-4.2.2.tgz#94c540e1ff772956e2299507c010aea6c8838eb0"
integrity sha512-KY9Frmirql91X2Qgjry0Wd4Y+YTdrdZheS8TFwvkbLWf/G5KNJDCh6pKL5OZctEW4+0Baa5idK2ZQuELRwPznQ==
dependencies:
punycode "^2.1.0"
v8-compile-cache@^2.0.3:
version "2.1.0"
resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.1.0.tgz#e14de37b31a6d194f5690d67efc4e7f6fc6ab30e"
integrity sha512-usZBT3PW+LOjM25wbqIlZwPeJV+3OSz3M1k1Ws8snlW39dZyYL9lOGC5FgPVHfk0jKmjiDV8Z0mIbVQPiwFs7g==
which@^1.2.9:
version "1.3.1"
resolved "https://registry.yarnpkg.com/which/-/which-1.3.1.tgz#a45043d54f5805316da8d62f9f50918d3da70b0a"
integrity sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==
dependencies:
isexe "^2.0.0"
wordwrap@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb"
integrity sha1-J1hIEIkUVqQXHI0CJkQa3pDLyus=
wrappy@1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"
integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=
write@1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/write/-/write-1.0.3.tgz#0800e14523b923a387e415123c865616aae0f5c3"
integrity sha512-/lg70HAjtkUgWPVZhZcm+T4hkL8Zbtp1nFNOn3lRrxnlv50SRBv7cR7RqR+GMsd3hUXy9hWBo4CHTbFTcOYwig==
dependencies:
mkdirp "^0.5.1"