mirror of
https://github.com/RoboSats/robosats.git
synced 2025-09-13 00:56:22 +00:00
17 lines
585 B
JavaScript
17 lines
585 B
JavaScript
// sort of cryptographically strong function to generate Base62 token client-side
|
|
export function genBase62Token(length){
|
|
return window.btoa(Array.from(
|
|
window.crypto.getRandomValues(
|
|
new Uint8Array(length * 2)))
|
|
.map((b) => String.fromCharCode(b))
|
|
.join("")).replace(/[+/]/g, "")
|
|
.substring(0, length);
|
|
}
|
|
|
|
export function tokenStrength(token) {
|
|
const characters = token.split("").reduce(function(obj, s){
|
|
obj[s] = (obj[s] || 0) + 1;
|
|
return obj;
|
|
}, {});
|
|
return {uniqueValues:Object.keys(characters).length,counts:Object.values(characters)}
|
|
} |