@ledgerhq/live-common
Version:
Common ground for the Ledger Live apps
26 lines (22 loc) • 555 B
text/typescript
import { sha256 } from "./crypto";
const userHashesPerUserId = (userId: string) => {
const firmwareSalt = sha256(userId + "|firmwareSalt")
.toString("hex")
.slice(0, 6);
const endpointOverrides100 = sha256(userId + "|endpoint").readUInt16BE(0) % 100;
return {
firmwareSalt,
endpointOverrides100,
};
};
let cache;
export const getUserHashes = (userId: string) => {
if (cache && userId === cache.userId) {
return cache.value;
}
cache = {
userId,
value: userHashesPerUserId(userId),
};
return cache.value;
};