| … | … | @@ -393,6 +393,10 @@ class PearGitServer { |
| 393 | 393 | console.log('⚠️ Auth DISABLED - server is open to all!') |
| 394 | 394 | } |
| 395 | 395 | |
| 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 | |
| 396 | 400 | // Initialize deployer (connects to Pear sidecar) |
| 397 | 401 | try { |
| 398 | 402 | await this.deployer.ready() |
| … | … | @@ -580,6 +584,57 @@ class PearGitServer { |
| 580 | 584 | }) |
| 581 | 585 | } |
| 582 | 586 | |
| 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 | |
| 583 | 638 | /** |
| 584 | 639 | * Join old Autobase discovery keys so legacy peers (pre-unified code) can connect. |
| 585 | 640 | * Derives discovery keys from stored bootstrap keys using hypercore-crypto. |