-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot-fleet.ts
More file actions
24 lines (18 loc) · 833 Bytes
/
Copy pathbot-fleet.ts
File metadata and controls
24 lines (18 loc) · 833 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
import { fromMnemonic, derive, recover } from 'nsec-tree'
const MNEMONIC =
'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about'
const root = fromMnemonic(MNEMONIC)
console.log('=== nsec-tree: bot fleet ===\n')
console.log('Deriving 10 bot identities from one seed:\n')
const bots = Array.from({ length: 10 }, (_, i) => derive(root, 'bot', i))
for (const bot of bots) {
console.log(` bot/${bot.index}: ${bot.npub}`)
}
// Recovery: scan the 'bot' purpose to rediscover all 10
console.log('\nRecovering bot fleet from seed...\n')
const found = recover(root, ['bot'], 10)
const recovered = found.get('bot')!
console.log(` Recovered ${recovered.length} bots`)
console.log(` All match? ${bots.every((b, i) => b.npub === recovered[i]!.npub)}`)
root.destroy()
console.log('\n Done.')