2025-03-04 08:07:27 -05:00
|
|
|
// lib/initNDK.ts
|
|
|
|
import 'react-native-get-random-values'; // This must be the first import
|
|
|
|
import NDK, { NDKCacheAdapterSqlite } from '@nostr-dev-kit/ndk-mobile';
|
|
|
|
import * as SecureStore from 'expo-secure-store';
|
|
|
|
|
2025-03-06 16:34:50 -05:00
|
|
|
// Use the same default relays you have in your current implementation
|
2025-03-04 08:07:27 -05:00
|
|
|
const DEFAULT_RELAYS = [
|
|
|
|
'wss://powr.duckdns.org',
|
|
|
|
'wss://relay.damus.io',
|
|
|
|
'wss://relay.nostr.band',
|
2025-03-06 16:34:50 -05:00
|
|
|
'wss://purplepag.es',
|
2025-03-04 08:07:27 -05:00
|
|
|
'wss://nos.lol'
|
|
|
|
];
|
|
|
|
|
|
|
|
export async function initializeNDK() {
|
|
|
|
console.log('Initializing NDK with mobile adapter...');
|
|
|
|
|
2025-03-06 16:34:50 -05:00
|
|
|
// Create a mobile-specific cache adapter
|
|
|
|
const cacheAdapter = new NDKCacheAdapterSqlite('powr', 1000);
|
2025-03-04 08:07:27 -05:00
|
|
|
|
|
|
|
// Initialize NDK with mobile-specific options
|
|
|
|
const ndk = new NDK({
|
|
|
|
cacheAdapter,
|
|
|
|
explicitRelayUrls: DEFAULT_RELAYS,
|
|
|
|
enableOutboxModel: true,
|
|
|
|
clientName: 'powr',
|
|
|
|
});
|
|
|
|
|
|
|
|
// Initialize cache adapter
|
|
|
|
await cacheAdapter.initialize();
|
|
|
|
|
|
|
|
// Connect to relays
|
|
|
|
await ndk.connect();
|
|
|
|
|
2025-03-06 16:34:50 -05:00
|
|
|
return { ndk };
|
2025-03-04 08:07:27 -05:00
|
|
|
}
|