import { createMobileGitCredentialKey, mobileGitCredentialState, parseMobileGitCredentialRecord, serializeMobileGitCredentialRecord, type MobileGitCredentialRecord, type MobileGitCredentialStorage, } from './mobileGitCredentialStorage' export type MobileSecureStore = { deleteItemAsync: (key: string) => Promise getItemAsync: (key: string) => Promise setItemAsync: (key: string, value: string) => Promise } export function createMobileSecureGitCredentialStorage( secureStore: MobileSecureStore, ): MobileGitCredentialStorage { return { loadState: async (requirement) => mobileGitCredentialState({ record: parseMobileGitCredentialRecord(await secureStore.getItemAsync(createMobileGitCredentialKey(requirement))), requirement, }), remove: async (requirement) => { await secureStore.deleteItemAsync(createMobileGitCredentialKey(requirement)) }, saveRecord: async (record) => { await secureStore.setItemAsync(recordKey(record), serializeMobileGitCredentialRecord(record)) }, } } function recordKey(record: MobileGitCredentialRecord) { return createMobileGitCredentialKey({ host: record.host, strategy: record.strategy, }) }