mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-11-25 14:43:05 +09:00
Checkpoint: File edits
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
7c3d72e897
commit
5dfe341ba0
1 file changed
+92
@@ -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<string | null> {
|
||||
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<T>(
|
||||
cid: string,
|
||||
gateway: string = 'https://ipfs.io'
|
||||
): Promise<T | null> {
|
||||
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<boolean> {
|
||||
// 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');
|
||||
}
|
||||
Reference in new issue
Block a user