12 lines
505 B
TypeScript
12 lines
505 B
TypeScript
import { bytesToHex } from '@noble/ciphers/utils';
|
|
import { nip19 } from '@nostr/tools';
|
|
import { bech32m } from '@scure/base';
|
|
|
|
export function readInvite(invite: `${string}1${string}`) {
|
|
const decoded = bech32m.decode(invite, false);
|
|
if (decoded.prefix !== 'eveinvite') return false;
|
|
const hexBytes = bech32m.fromWords(decoded.words);
|
|
const npub = nip19.npubEncode(bytesToHex(hexBytes.slice(0, 32)));
|
|
const inviteCode = bytesToHex(hexBytes.slice(32));
|
|
return { npub, invite: inviteCode };
|
|
}
|