From 5dfe341ba0a521575f09eebd0356866a24e5b71a Mon Sep 17 00:00:00 2001 From: rUv Date: Thu, 8 Jan 2026 19:13:24 +0000 Subject: [PATCH] Checkpoint: File edits MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Automatic checkpoint created by Claude Code - Branch: v3 - Timestamp: 2026-01-08T19:13:24Z - Changes: 1 file(s) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .../cli/src/transfer/ipfs/client.ts | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 v3/@claude-flow/cli/src/transfer/ipfs/client.ts diff --git a/v3/@claude-flow/cli/src/transfer/ipfs/client.ts b/v3/@claude-flow/cli/src/transfer/ipfs/client.ts new file mode 100644 index 0000000000..f048759765 --- /dev/null +++ b/v3/@claude-flow/cli/src/transfer/ipfs/client.ts @@ -0,0 +1,92 @@ +/** + * IPFS Client Module + * Low-level IPFS operations for discovery and fetching + */ + +import * as crypto from 'crypto'; + +/** + * Resolve IPNS name to CID + * In production: Use ipfs-http-client or similar + */ +export async function resolveIPNS( + ipnsName: string, + gateway: string = 'https://ipfs.io' +): Promise { + console.log(`[IPFS] Resolving IPNS: ${ipnsName}`); + + // In production: Use IPNS resolution + // For demo: Return null to trigger fallback to demo registry + try { + // Simulate IPNS resolution delay + await new Promise(resolve => setTimeout(resolve, 100)); + + // For demo purposes, return null to use local demo data + // In production, this would do actual IPNS resolution + return null; + } catch (error) { + console.warn(`[IPFS] IPNS resolution failed:`, error); + return null; + } +} + +/** + * Fetch content from IPFS by CID + * In production: Use ipfs-http-client or gateway fetch + */ +export async function fetchFromIPFS( + cid: string, + gateway: string = 'https://ipfs.io' +): Promise { + console.log(`[IPFS] Fetching CID: ${cid}`); + + try { + // Simulate fetch delay + await new Promise(resolve => setTimeout(resolve, 100)); + + // For demo purposes, return null to use local demo data + // In production, this would fetch from IPFS gateway + // const url = `${gateway}/ipfs/${cid}`; + // const response = await fetch(url); + // return await response.json(); + + return null; + } catch (error) { + console.warn(`[IPFS] Fetch failed:`, error); + return null; + } +} + +/** + * Check if CID is pinned + */ +export async function isPinned( + cid: string, + gateway: string = 'https://ipfs.io' +): Promise { + // In production: Check with pinning service + return false; +} + +/** + * Get IPFS gateway URL for a CID + */ +export function getGatewayUrl(cid: string, gateway: string = 'https://ipfs.io'): string { + return `${gateway}/ipfs/${cid}`; +} + +/** + * Validate CID format + */ +export function isValidCID(cid: string): boolean { + // CIDv0 starts with 'Qm' and is 46 characters + // CIDv1 starts with 'b' (base32) and varies in length + return /^(Qm[1-9A-HJ-NP-Za-km-z]{44}|b[a-z2-7]{58,})$/.test(cid); +} + +/** + * Generate content hash for verification + */ +export function hashContent(content: Buffer): string { + return crypto.createHash('sha256').update(content).digest('hex'); +}