mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-06 19:02:33 +01:00
Merge pull request #526 from erkinalp/patch-3
This commit is contained in:
commit
c0b020e34a
@ -16,16 +16,17 @@ export function random(length = 6) {
|
|||||||
export function snowflakeBasedInvite() {
|
export function snowflakeBasedInvite() {
|
||||||
// Declare all characters
|
// Declare all characters
|
||||||
let chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
let chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||||
|
let base = BigInt(chars.length);
|
||||||
let snowflake = Snowflake.generateWorkerProcess();
|
let snowflake = Snowflake.generateWorkerProcess();
|
||||||
|
|
||||||
// snowflakes hold ~10.75 characters worth of entropy;
|
// snowflakes hold ~10.75 characters worth of entropy;
|
||||||
// safe to generate a 8-char invite out of them
|
// safe to generate a 8-char invite out of them
|
||||||
let str = "";
|
let str = "";
|
||||||
for (let i=0; i < 10; i++) {
|
for (let i=0; i < 10; i++) {
|
||||||
str += chars.charAt((snowflake % chars.length));
|
|
||||||
snowflake /= chars.length;
|
str += chars.charAt(snowflake % base);
|
||||||
|
snowflake = snowflake / base;
|
||||||
}
|
}
|
||||||
|
|
||||||
return str.substr(3,8).reverse(); // little-endianise for entropy
|
return str.substr(3,8).split("").reverse().join("");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user