CCN invitation and write permissions to CCN
This commit is contained in:
parent
a8ffce918e
commit
36c7401fa8
5 changed files with 395 additions and 107 deletions
12
utils/invites.ts
Normal file
12
utils/invites.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
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 };
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue