-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ada822b
commit c8122d1
Showing
4 changed files
with
21 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import crypto from "crypto"; | ||
|
||
const ALPHABET = "23456789ABCDEFGHJKLMNPQRSTUVWXYZ"; | ||
|
||
export function generateChannelToken(length = 8): string { | ||
const bytes = crypto.randomBytes(length); | ||
let id = ""; | ||
for (let i = 0; i < length; i++) { | ||
const byte = bytes[i]; | ||
if (byte === undefined) { | ||
throw new Error("Error generating channel token"); | ||
} | ||
id += ALPHABET[byte % ALPHABET.length]; | ||
} | ||
return id; | ||
} |