OverviewFilesCommitsIssuesDocsReleasesPeers

wirecore commits / 63fdd73

Fix ANProto Phase 1 bugs
Fixed three bugs in ANProto identity implementation: 1. Display bug: publicKey showing as Buffer instead of base64 string - Fixed cmdInit() to use b4a.toString(publicKey, 'base64') 2. Storage bug: loadState() not finding ANProto storage - Reordered loadState() to check for ANProto keypair FIRST - Old system check moved to fallback 3. Web server bug: Not checking for ANProto keypair - Updated startWebServer() to check both anprotoKeypair and identity Testing: - ✅ init creates ANProto keypair, displays base64 public key - ✅ whoami loads ANProto keypair from storage successfully - ✅ web starts server and shows ANProto identity Released: pear://zupx3qzpwj61hdt1bxanabctcyxqqu3arogctwim4qt3wfbzn4bo Version: 4087 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
63fdd7308c6cd0d523b47363aa39d868f4e492ef
by plankatron <fleeky@gmail.com> · 2026-01-21T17:32:03.000Z

Changed files (2) +42 -32

pear-app/.pearignore +4 -0
……@@ -2,6 +2,10 @@
22# CRITICAL: Do NOT ignore node_modules (module resolution bug under pear://)
33# But we CAN ignore unnecessary files WITHIN node_modules
44
5# IMPORTANT: Explicitly include public directory (web UI files)
6!public/
7!public/**
8
59# Development files
610.git
711.gitignore
pear-app/index.js +38 -32
……@@ -66,48 +66,56 @@ async function loadState() {
6666 if (store) return true // Already loaded
6767
6868 // Try to open Corestore - if it fails, storage doesn't exist yet
69 let identityCore
7069 try {
7170 store = new Corestore(STORAGE_PATH)
7271 await store.ready()
7372
74 // Load identity
75 identityCore = store.get({ name: 'identity' })
73 // Load metadata first (needed for both systems)
74 metaBee = new Hyperbee(store.get({ name: 'metadata' }), {
75 keyEncoding: 'utf-8',
76 valueEncoding: 'json'
77 })
78 await metaBee.ready()
79
80 // Check for ANProto keypair (new system) FIRST
81 const keypairNode = await metaBee.get('anproto-keypair')
82 if (keypairNode && keypairNode.value) {
83 // New ANProto system found
84 const keypairStr = keypairNode.value
85 const { publicKey, secretKey } = ANProto.loadKeypair(keypairStr)
86 anprotoKeypair = { publicKey, secretKey }
87
88 // Load feed using ANProto keypair
89 myFeed = store.get({
90 publicKey: anprotoKeypair.publicKey,
91 secretKey: anprotoKeypair.secretKey
92 })
93 await myFeed.ready()
94
95 // User Hyperdrive will be created lazily when first image is uploaded
96 return true
97 }
98
99 // Fallback: try old IdentityKey system
100 const identityCore = store.get({ name: 'identity' })
76101 await identityCore.ready()
77102
78103 if (identityCore.length === 0) {
104 // Not initialized at all
79105 await store.close()
80106 store = null
81 return null // Not initialized
107 metaBee = null
108 return null
82109 }
83110
111 // Old system exists
84112 const identitySeed = await identityCore.get(0)
85113 identity = await IdentityKey.from({ seed: identitySeed })
86114
87 // Load personal feed
115 // Load personal feed (old system uses named feed)
88116 myFeed = store.get({ name: 'my-feed' })
89117 await myFeed.ready()
90118
91 // Load metadata
92 metaBee = new Hyperbee(store.get({ name: 'metadata' }), {
93 keyEncoding: 'utf-8',
94 valueEncoding: 'json'
95 })
96 await metaBee.ready()
97
98 // Try to load ANProto keypair (new system)
99 try {
100 const keypairNode = await metaBee.get('anproto-keypair')
101 if (keypairNode && keypairNode.value) {
102 const keypairStr = keypairNode.value
103 const { publicKey, secretKey } = ANProto.loadKeypair(keypairStr)
104 anprotoKeypair = { publicKey, secretKey }
105 }
106 } catch (err) {
107 // No ANProto keypair yet (old system or not initialized)
108 anprotoKeypair = null
109 }
110
111119 // User Hyperdrive will be created lazily when first image is uploaded
112120 return true
113121 } catch (err) {
……@@ -250,10 +258,8 @@ async function cmdInit() {
250258
251259 // Generate ANProto keypair
252260 const { keypair, publicKey, secretKey } = ANProto.gen()
253 anprotoKeypair = {
254 publicKey: b4a.from(publicKey, 'base64'),
255 secretKey: b4a.from(secretKey, 'base64')
256 }
261 // Note: publicKey and secretKey from gen() are Buffers
262 anprotoKeypair = { publicKey, secretKey }
257263
258264 // Create personal feed using ANProto keypair
259265 // This unifies identity: ANProto public key = Hypercore feed key
……@@ -276,7 +282,7 @@ async function cmdInit() {
276282 await metaBee.put('profile', { username: null })
277283
278284 console.log('✅ Wirecore initialized with ANProto!')
279 console.log('ANProto public key:', publicKey)
285 console.log('ANProto public key:', b4a.toString(publicKey, 'base64'))
280286 console.log('Feed key (same as ANProto key):', b4a.toString(myFeed.key, 'hex'))
281287 console.log('')
282288 console.log('💡 Set your username with: pear run . cli setname "YourName"')
……@@ -875,8 +881,8 @@ const wsClients = new Set()
875881async function startWebServer(port = 3003) {
876882 await loadState()
877883
878 if (!identity) {
879 console.error('❌ Not initialized. Run: pear run . init')
884 if (!anprotoKeypair && !identity) {
885 console.error('❌ Not initialized. Run: pear run . cli init')
880886 return
881887 }
882888