OverviewFilesCommitsIssuesDocsReleasesPeers

pear-git commits / 5e5ef4d

Auto-register local peer Noise key for P2P push auth
On startup, reads ~/.config/pear-git/peer-identity.json (created by pgh/git-remote-punch) and registers it as a noise-key identity linked to an admin user in MetadataBase. Uses repairIdentity to ensure the noisekey: reverse lookup exists even if the identity record was migrated without it. This allows git push punch:// from the local machine without manual peer-access setup. The existing _validateRepo fallback checks NoiseKeyProvider for admin status, which now finds the registered key. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5e5ef4d35a6e877e05ec35261d7dd9e29749b66d
by plankatron <fleeky@gmail.com> · 2026-04-06T14:04:24.000Z

Changed files (1) +55 -0

pear-git-server.js +55 -0
……@@ -393,6 +393,10 @@ class PearGitServer {
393393 console.log('⚠️ Auth DISABLED - server is open to all!')
394394 }
395395
396 // Auto-register local peer Noise key as admin identity.
397 // This allows P2P push from the same machine (git push punch://).
398 await this._registerLocalPeerKey()
399
396400 // Initialize deployer (connects to Pear sidecar)
397401 try {
398402 await this.deployer.ready()
……@@ -580,6 +584,57 @@ class PearGitServer {
580584 })
581585 }
582586
587 /**
588 * Auto-register the local peer Noise key as an admin identity.
589 * Reads ~/.config/pear-git/peer-identity.json (created by pgh/git-remote-punch)
590 * and registers it in the MetadataBase so P2P push from this machine works.
591 */
592 async _registerLocalPeerKey () {
593 try {
594 const peerIdentityPath = path.join(os.homedir(), '.config', 'pear-git', 'peer-identity.json')
595 let peerData
596 try {
597 peerData = JSON.parse(fs.readFileSync(peerIdentityPath, 'utf-8'))
598 } catch {
599 return // No peer identity — pgh hasn't been used yet
600 }
601
602 if (!peerData.publicKey) return
603
604 const publicKeyHex = peerData.publicKey
605
606 // Check if noise-key reverse lookup exists (not just identity record)
607 const existing = await this.identityRegistry.getIdentityByNoiseKey(publicKeyHex)
608 if (existing) {
609 console.log(`[P2P] Local peer key already registered (${publicKeyHex.slice(0, 12)}...)`)
610 return
611 }
612
613 // Find an admin user to link to
614 const allUsers = await this.identityRegistry.listAllUsers()
615 const adminUser = allUsers.find(u =>
616 u.globalPermissions && u.globalPermissions.includes('admin')
617 )
618
619 if (!adminUser) {
620 console.log('[P2P] No admin user found — cannot auto-register local peer key')
621 return
622 }
623
624 // Register (or repair) the Noise key identity — ensures reverse lookup exists
625 await this.identityRegistry.repairIdentity({
626 identityId: `noise:${publicKeyHex}`,
627 method: 'noise-key',
628 userId: adminUser.userId,
629 credentials: { publicKey: publicKeyHex }
630 })
631
632 console.log(`✓ Local peer key registered for P2P push (${publicKeyHex.slice(0, 12)}... → ${adminUser.userId.slice(0, 8)})`)
633 } catch (err) {
634 console.error('[P2P] Failed to auto-register local peer key:', err.message)
635 }
636 }
637
583638 /**
584639 * Join old Autobase discovery keys so legacy peers (pre-unified code) can connect.
585640 * Derives discovery keys from stored bootstrap keys using hypercore-crypto.