-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathidentity.ts
More file actions
33 lines (28 loc) · 828 Bytes
/
Copy pathidentity.ts
File metadata and controls
33 lines (28 loc) · 828 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { generateSecretKey, getPublicKey } from 'nostr-tools'
import * as nip19 from 'nostr-tools/nip19'
export const GENUS = 'Replicator'
export const EPITHET = 'deus'
export const SPECIES_NAME = `${GENUS} ${EPITHET}`
export type Keypair = {
sk: Uint8Array
nsec: string
npub: string
pubkeyHex: string
}
export function keypairFromSecretKey(sk: Uint8Array): Keypair {
const pubkeyHex = getPublicKey(sk)
return {
sk,
nsec: nip19.nsecEncode(sk),
npub: nip19.npubEncode(pubkeyHex),
pubkeyHex,
}
}
export function generateKeypair(): Keypair {
return keypairFromSecretKey(generateSecretKey())
}
export function decodeNsec(nsec: string): Uint8Array {
const decoded = nip19.decode(nsec)
if (decoded.type !== 'nsec') throw new Error(`not an nsec: ${nsec}`)
return decoded.data as Uint8Array
}