mirror of
https://github.com/block/buzz.git
synced 2026-11-11 20:01:09 +00:00
Signed-off-by: Wes <wesbillman@users.noreply.github.com> Co-authored-by: Pinky <44b8e82baa6e0e254e0208d68f335c283c94e7b78dd1fa10d5a49d3f13dd0435@sprout-oss.stage.blox.sqprod.co> Co-authored-by: Brain <21994759fc7a6fa6b965551d35cfd7897d262f2495467f2d78694ddcfa6a5c7e@sprout-oss.stage.blox.sqprod.co>
26 lines
914 B
TypeScript
26 lines
914 B
TypeScript
/**
|
|
* Canonical pubkey normalisation.
|
|
*
|
|
* Hex pubkeys are case-insensitive, but callers compare them with `===`.
|
|
* Trimming guards against stray whitespace from user input or tag parsing.
|
|
*/
|
|
export function normalizePubkey(pubkey: string): string {
|
|
return pubkey.trim().toLowerCase();
|
|
}
|
|
|
|
/**
|
|
* The ONE canonical compact display form for a pubkey: `abcd1234…wxyz`.
|
|
*
|
|
* A truncated pubkey is a recognition aid, never an identity proof — vanity
|
|
* grinders forge short prefixes cheaply. Surfaces where the user makes a
|
|
* trust decision must show the full npub (see `<PubKey variant="full">`).
|
|
* Do not hand-roll `pubkey.slice(…)` display forms; `check-pubkey-truncation`
|
|
* fails the build if one sneaks in outside this module.
|
|
*/
|
|
export function truncatePubkey(pubkey: string): string {
|
|
if (pubkey.length <= 12) {
|
|
return pubkey;
|
|
}
|
|
return `${pubkey.slice(0, 8)}…${pubkey.slice(-4)}`;
|
|
}
|