@@ -3,7 +3,8 @@ import { join, relative, basename } from 'path';
33import ora from 'ora' ;
44import inquirer from 'inquirer' ;
55import { KeyManager , SignatureManager } from '@frw/crypto' ;
6- import { IPFSClient } from '@frw/ipfs' ;
6+ import { IPFSClient , DistributedNameRegistry , createDistributedNameRecord } from '@frw/ipfs' ;
7+ import { ProofOfWorkGenerator , getRequiredDifficulty } from '@frw/name-registry' ;
78import { config } from '../utils/config.js' ;
89import { logger } from '../utils/logger.js' ;
910
@@ -134,6 +135,59 @@ export async function publishCommand(directory: string = '.', options: PublishOp
134135 logger . debug ( 'You can still access via CID' ) ;
135136 }
136137
138+ // Update distributed registry if name specified
139+ if ( options . name ) {
140+ spinner . start ( 'Updating name registry...' ) ;
141+ try {
142+ // Get registered name info from config
143+ const registeredNames = config . get ( 'registeredNames' ) || { } ;
144+ if ( ! registeredNames [ options . name ] ) {
145+ spinner . warn ( `Name "${ options . name } " not registered. Run: frw register ${ options . name } ` ) ;
146+ } else {
147+ // Create updated record with new contentCID
148+ const ipnsKey = `/ipns/${ publicKeyEncoded } ` ;
149+ const record = createDistributedNameRecord (
150+ options . name ,
151+ publicKeyEncoded ,
152+ rootCID , // NEW contentCID
153+ ipnsKey ,
154+ keyPair . privateKey ,
155+ { nonce : 0 , hash : '' , difficulty : 0 , timestamp : Date . now ( ) } , // Dummy PoW for update
156+ 365 * 24 * 60 * 60 * 1000
157+ ) ;
158+
159+ // Submit to bootstrap nodes
160+ const registry = new DistributedNameRegistry ( {
161+ bootstrapNodes : [
162+ 'http://83.228.214.189:3100' ,
163+ 'http://localhost:3100'
164+ ]
165+ } ) ;
166+
167+ // Use direct submission (simpler than updateContent which needs resolution)
168+ const nodes = [ 'http://83.228.214.189:3100' ] ;
169+ for ( const node of nodes ) {
170+ try {
171+ const response = await fetch ( `${ node } /api/submit` , {
172+ method : 'POST' ,
173+ headers : { 'Content-Type' : 'application/json' } ,
174+ body : JSON . stringify ( record )
175+ } ) ;
176+ if ( response . ok ) {
177+ spinner . succeed ( 'Name registry updated' ) ;
178+ break ;
179+ }
180+ } catch ( err ) {
181+ // Continue to next node
182+ }
183+ }
184+ }
185+ } catch ( error ) {
186+ spinner . warn ( 'Registry update failed' ) ;
187+ logger . debug ( error instanceof Error ? error . message : String ( error ) ) ;
188+ }
189+ }
190+
137191 // Display results
138192 logger . section ( 'Publish Complete' ) ;
139193 logger . success ( 'Content published successfully!' ) ;
0 commit comments