Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change generated project name to become /^(random_word)-[0-9a-z]{6}$/ #4649

Conversation

pkong-ds
Copy link
Contributor

@pkong-ds pkong-ds commented Aug 23, 2024

ref DEV-1612

Uncertainty

whether we want uppercase or not

EDIT: resolved, lower case only

No uppercase characters. The project is used in the domain name, and you know domain case is case-insensitive.

Preview

Screen.Recording.2024-08-23.at.4.43.08.PM.mp4

@pkong-ds pkong-ds force-pushed the dev-1612-improve-random-project-name-generator branch from a937313 to 5018f95 Compare August 23, 2024 08:43
@pkong-ds pkong-ds changed the title Change generated project name to become /^(random_word)-[0-9a-zA-z]{6}$/ Change generated project name to become /^(random_word)-[0-9a-z]{6}$/ Aug 23, 2024
@pkong-ds pkong-ds force-pushed the dev-1612-improve-random-project-name-generator branch from 5018f95 to 1acee9b Compare August 23, 2024 09:41
@louischan-oursky louischan-oursky self-requested a review August 26, 2024 03:49
@louischan-oursky louischan-oursky self-assigned this Aug 26, 2024
}
return result;
}

export function deterministicProjectName(num: number): string {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is deterministic. You now make it indeterministic.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10, 11, 11 = 32bit

11, 21 = 32bit

first 11 bit => BIP39 word
last 31 bit => base36(26 lower+ 10digit) encode 31 bits => log36(2 ^ 31) <= 6

toString(36) with left-padded zeros

11 => BIP39 word
21 => base36 (26 lower + 10 digit) encode 21 bits => log36(2^21) <= 5

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per offline discussion, we can the algorithm to take 42 random bits

first 11 bits => BIP39 word
remaining 31 bits => base36 encode the 31 bits to form a alphanumeric string of length 6. Zero-pad it to make it always of length 6.

@@ -15,15 +17,25 @@ export function maskNumber(num: number, startAt: number, bits: number): number {
return (num >> startAt) & ((1 << bits) - 1);
}

export function getRandomAlphaNumericString(len: number): string {
let result = "";
const chars = "abcdefghijklmnopqrstuvwxyz0123456789";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0123456789abc....

@pkong-ds pkong-ds force-pushed the dev-1612-improve-random-project-name-generator branch 2 times, most recently from 6fb1d51 to 844ae7a Compare August 26, 2024 07:37
@pkong-ds pkong-ds force-pushed the dev-1612-improve-random-project-name-generator branch from 844ae7a to e591b8c Compare August 26, 2024 07:37
@pkong-ds
Copy link
Contributor Author

Updated, thanks!

import {
deterministicProjectName,
extractBits,
maskNumber,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete maskNumber and its test. It is no longer used.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add

export function projectNameOfCompanyName(companyName: string): string {
  const bytes = random();
  const [_unused, toBeUsed] = extractBits(bytes);
  return `${companyName}-${}`;
}

import {
deterministicProjectName,
extractBits,
maskNumber,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add

export function projectNameOfCompanyName(companyName: string): string {
  const bytes = random();
  const [_unused, toBeUsed] = extractBits(bytes);
  return `${companyName}-${}`;
}

@pkong-ds
Copy link
Contributor Author

Updated, thanks!

@louischan-oursky louischan-oursky self-requested a review August 26, 2024 08:09
@louischan-oursky louischan-oursky merged commit 5c08f40 into authgear:main Aug 26, 2024
5 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants